Apply filter to an Image Introduction
Apply filtering effects to an existing image.
Following Filter types are supported:
BigRectangular;
SmallRectangular;
Median;
GaussWiener;
MotionWiener;
GaussianBlur;
Sharpen;
BilateralSmoothing.
There are two APIs to crop an image:
The API expects you to first upload an image to Cloud Storage then pass its name in the API URL. After updating the image parameters, the API returns the updated image in the response. If you would like to save the updated image on the Cloud Storage, you explicitly need to do this as shown in the below examples.
Resource URI
Aspose.Imaging Cloud APIs Swagger UI lets you call REST APIs directly from the browser. The description of the API and its parameters are also given there.
cURL Example
SDKs
Using an SDK (API client) is the quickest way for a developer to speed up the development. An SDK takes care of a lot of low-level details of making requests and handling responses and lets you focus on writing code specific to your particular project. Check out our GitHub repository for a complete list of Aspose.Imaging Cloud SDKs along with working examples, to get you started in no time. Please check Available SDKs article to learn how to add an SDK to your project.
SDK Examples
.NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to aspose-imaging-cloud-dotnet/Examples/AsposeImagingCloudSdkExamples
public void GrayscaleImageFromStorage()
{
// Input formats could be one of the following:
// BMP, GIF, DJVU, WMF, EMF, JPEG, JPEG2000, PSD, TIFF, WEBP, PNG, DICOM, CDR, CMX, ODG, DNG and SVG
string sampleImageFileName = "FilterEffectSampleImage.psd";
// Upload local image to Cloud Storage
using (var localInputImage = File.OpenRead(Path.Combine(ExampleImagesFolder, sampleImageFileName)))
{
var uploadFileRequest = new UploadFileRequest(Path.Combine(CloudPath, imageName), image);
var result = ImagingApi.UploadFile(uploadFileRequest);
}
var filterType = "GaussianBlur";
var filterProperties = new GaussianBlurFilterProperties
{
Radius = 4,
Sigma = 2.1
};
var format = "bmp";
var folder = CloudPath; // Input file is saved at the Examples folder in the storage
string storage = null; // We are using default Cloud Storage
var filterEffectRequest = new FilterEffectImageRequest(SampleImageFileName, filterType, filterProperties,
format, folder, storage);
using (Stream updatedImage = this.ImagingApi.FilterEffectImage(filterEffectRequest))
{
// Save updated image to local storage
using (var fileStream = File.Create(Path.Combine(ExampleImagesFolder, "FilterEffectSampleImage_out.bmp")))
{
updatedImage.Seek(0, SeekOrigin.Begin);
updatedImage.CopyTo(fileStream);
}
}
}
Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void GrayscaleImageFromStorage() throws Exception {
String fileName = "FilterEffectSampleImage.psd";
byte[] inputImage = Files.readAllBytes(Paths.get(ExampleImagesFolder, fileName));
UploadFileRequest request = new UploadFileRequest(Paths.get(CloudPath, fileName).toString(), image, null);
FilesUploadResult response = ImagingApi.uploadFile(request);
String filterType = "GaussianBlur";
GaussianBlurFilterProperties filterProperties = new GaussianBlurFilterProperties() {{
setRadius(4);
setSigma(2.1);
}};
String format = "bmp";
String folder = CloudPath; // Input file is saved at the Examples folder in the storage
String storage = null; // We are using default Cloud Storage
FilterEffectImageRequest request = new FilterEffectImageRequest(getSampleImageFileName(), filterType,
filterProperties, format, folder, storage);
byte[] updatedImage = ImagingApi.filterEffectImage(request);
Path path = Paths.get(OutputFolder, "GrayscaleSampleImage_out.bmp").toAbsolutePath();
Files.write(path, updatedImage);
}