Update Parameters of WEBP Image Introduction
This article explains how to update the parameters of existing WEBP image. The API lets you update image properties such as quality, animation loop count, animation background color and lossless. Image parameters can be updated using one of the following two APIs:
The first 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.
On the other hand, with the second API, you can directly pass the image in the request body. It also lets you save the updated image on the Cloud Storage by specifying the outPath parameter value. However, if you do not specify the value, the response contains a streamed image.
Resource URI
With Swagger UI you can call Aspose.Imaging REST APIs directly from the browser. Description of an API and its parameters are also provided 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 https://github.com/aspose-imaging-cloud/aspose-imaging-cloud-dotnet
public void ModifyWebPFromStorage()
{
String fileName = "asposelogo.webp";
// Upload local image to Cloud Storage
using (FileStream localInputImage = File.OpenRead(ImagingBase.PathToDataFiles + fileName))
{
var uploadFileRequest = new UploadFileRequest(fileName, localInputImage);
FilesUploadResult result = this.ImagingApi.UploadFile(uploadFileRequest);
}
bool? lossless = true;
int? quality = 90;
int? animLoopCount = 5;
string animBackgroundColor = "gray";
// Specifies where additional parameters we do not support should be taken from.
// If this is true – they will be taken from default values for standard image,
// if it is false – they will be saved from current image. Default is false.
bool? fromScratch = null;
string folder = null; // Folder with image to process. The value is null because the file is saved at the root of the storage
String storage = null; // We are using default Cloud Storage
ModifyWebPRequest getImageWebPRequest = new ModifyWebPRequest(fileName, lossless, quality,
animLoopCount, animBackgroundColor, fromScratch, folder, storage);
Stream updatedImage = this.ImagingApi.ModifyWebP(getImageWebPRequest);
// Save updated image to local storage
using (var fileStream = File.Create(ImagingBase.PathToDataFiles + "asposelogo_out.webp"))
{
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
String APP_KEY = ""; // Get AppKey and AppSID from https:dashboard.aspose.cloud/
String APP_SID = ""; // Get AppKey and AppSID from https:dashboard.aspose.cloud/
String DATA_PATH = "src/main/resources/";
ImagingApi imagingApi = new ImagingApi(APP_KEY, APP_SID);
String fileName = "asposelogo.webp";
try {
// Upload local image to Cloud Storage
File inputFile = new File(Main.DATA_PATH + fileName);
FileInputStream localInputImageStream = new FileInputStream(inputFile);
byte[] localInputImage = IOUtils.toByteArray(localInputImageStream);
UploadFileRequest uploadFileRequest = new UploadFileRequest(fileName, localInputImage, null);
FilesUploadResult result = imagingApi.uploadFile(uploadFileRequest);
Boolean lossless = true;
Integer quality = 90;
Integer animLoopCount = 5;
String animBackgroundColor = "gray";
// Specifies where additional parameters we do not support should be taken from.
// If this is true – they will be taken from default values for standard image,
// if it is false – they will be saved from current image. Default is false.
Boolean fromScratch = null;
String outPath = null; // Path to updated file (if this is empty, response contains streamed image).
// Folder with image to process. The value is null because the file is saved at the root of the storage
String folder = null;
String storage = null; // We are using default Cloud Storage
GetImageWebPRequest getImageWebPRequest = new GetImageWebPRequest(fileName, lossless, quality,
animLoopCount, animBackgroundColor, fromScratch, outPath, folder, storage);
byte[] updatedImage = imagingApi.getImageWebP(getImageWebPRequest);
// Save updated image to local storage
FileOutputStream fos = new FileOutputStream(Main.DATA_PATH + "asposelogo_out.webp");
fos.write(updatedImage);
fos.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
.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 https://github.com/aspose-imaging-cloud/aspose-imaging-cloud-dotnet
public void CreateModifiedWebPFromRequestBody()
{
string fileName = "asposelogo.webp";
using (FileStream inputImageStream = File.OpenRead(ImagingBase.PathToDataFiles + fileName))
{
bool? lossless = true;
int? quality = 90;
int? animLoopCount = 5;
string animBackgroundColor = "gray";
bool? fromScratch = null;
string outPath = null; // Path to updated file (if this is empty, response contains streamed image).
string storage = null; // We are using default Cloud Storage
CreateModifiedWebPRequest modifiedImageWebPRequest = new CreateModifiedWebPRequest(inputImageStream, lossless, quality,
animLoopCount, animBackgroundColor, fromScratch, outPath, storage);
Stream updatedImage = this.ImagingApi.CreateModifiedWebP(modifiedImageWebPRequest);
// Save updated image to local storage
using (var fileStream = File.Create(ImagingBase.PathToDataFiles + "asposelogo_out.webp"))
{
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
String APP_KEY = ""; // Get AppKey and AppSID from https:dashboard.aspose.cloud/
String APP_SID = ""; // Get AppKey and AppSID from https:dashboard.aspose.cloud/
String DATA_PATH = "src/main/resources/";
ImagingApi imagingApi = new ImagingApi(APP_KEY, APP_SID);
try {
File file = new File(Main.DATA_PATH + "asposelogo.webp");
byte[] imageData = Files.readAllBytes(file.toPath());
Boolean lossless = true;
Integer quality = 90;
Integer animLoopCount = 5;
String animBackgroundColor = "gray";
Boolean fromScratch = null;
String outPath = null; // Path to updated file (if this is empty, response contains streamed image).
String storage = null; // We are using default Cloud Storage
PostImageWebPRequest postImageWebPRequest = new PostImageWebPRequest(imageData, lossless, quality,
animLoopCount, animBackgroundColor, fromScratch, outPath, storage);
byte[] updatedImage = imagingApi.postImageWebP(postImageWebPRequest);
// Save updated image to local storage
FileOutputStream fos = new FileOutputStream(Main.DATA_PATH + "asposelogo_out.webp");
fos.write(updatedImage);
fos.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}