Deskew an Image Introduction
Deskew method allows to rotate an image to compensate for skewing.
There are two APIs to deskew an image:
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.
Please check Common Operations Format Support Map to know the supported conversion formats.
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 DeskewAnImageInCloud()
{
// 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 = "DeskewSampleImage.tif";
// 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);
}
bool resizeProportionally = true;
string bkColor = "white";
string folder = CloudPath; // Input file is saved at the Examples folder in the storage
string storage = null; // We are using default Cloud Storage
var request = new DeskewImageRequest(SampleImageFileName, resizeProportionally, bkColor, folder, storage);
using (Stream updatedImage = this.ImagingApi.DeskewImage(request))
{
// Save updated image to local storage
using (var fileStream = File.Create(Path.Combine(ExampleImagesFolder, "DeskewSampleImage_out.tiff")))
{
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 DeskewAnImageInCloud() throws Exception {
String fileName = "DeskewSampleImage.tif";
Boolean resizeProportionally = true;
String bkColor = "white";
String folder = CloudPath; // Input file is saved at the Examples folder in the storage
String storage = null; // We are using default Cloud Storage
DeskewImageRequest request = new DeskewImageRequest(getSampleImageFileName(), resizeProportionally, bkColor, folder, storage);
byte[] updatedImage = ImagingApi.deskewImage(request);
Path path = Paths.get(OutputFolder, "DeskewSampleImage_out.tif").toAbsolutePath();
Files.write(path, updatedImage);
}
.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/tree/master/Examples
public void DeskewAnImageInRequestBody()
{
// 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 = "DeskewSampleImage.tif";
using (FileStream inputImageStream = File.OpenRead(Path.Combine(ExampleImagesFolder, SampleImageFileName))
{
bool resizeProportionally = true;
string bkColor = "white";
string storage = null; // We are using default Cloud Storage
string outPath = null; // Path to updated file (if this is empty, response contains streamed image)
var request = new CreateDeskewedImageRequest(inputImageStream, resizeProportionally, bkColor, outPath, storage);
using (Stream updatedImage = this.ImagingApi.CreateDeskewedImage(request))
{
// Save updated image to local storage
using (var fileStream = File.Create(Path.Combine(ExampleImagesFolder, "GDeskewSampleImage_out.tif")))
{
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 DeskewAnImageInRequestBody() throws Exception {
String fileName = "DeskewSampleImage.tif";
Boolean resizeProportionally = true;
String bkColor = "white";
String storage = null; // We are using default Cloud Storage
String outPath = null; // Path to updated file (if this is empty, response contains streamed image)
byte[] inputStream = Files.readAllBytes(Paths.get(ExampleImagesFolder, getSampleImageFileName()));
CreateDeskewedImageRequest request = new CreateDeskewedImageRequest(inputStream, resizeProportionally, bkColor, outPath, storage);
byte[] updatedImage = ImagingApi.createDeskewedImage(request);
Path path = Paths.get(OutputFolder, "DeskewSampleImage_out.tif").toAbsolutePath();
Files.write(path, updatedImage);
}