resize Image

Resize TIFF Image using Java

We know that one of the prominent features of TIFF files is its capability to store multiple images (each having multiple channels) as sequential frames in a time-stack or z-stack of images. So in this article explains how to extract a frame from a TIFF image, resize it and save it separately on the storage. Resize operation requires new dimensions (Width & Height) for a specified TIFF Frame.

Resize Image API

Aspose.Imaging Cloud SDK for Java is our REST based solution offering the capabilities to programmatically edit, manipulate and transform raster, metafiles, photoshop to variety of Supported Formats. At the same time, is also offers the feature to manipulation TIFF images where we can even work on individual TIFF frame. Now in order to get started with SDK utilization, we need to add its reference in our java project by including following information in pom.xml (maven build type project).

<repositories> 
    <repository>
        <id>aspose-cloud</id>
        <name>artifact.aspose-cloud-releases</name>
        <url>http://artifact.aspose.cloud/repo</url>
    </repository>   
</repositories>

<dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-imaging-cloud</artifactId>
        <version>22.4</version>
    </dependency>
</dependencies>

The next step is to obtain client credentials details from Cloud Dashboard and if you do not have an account over Aspose Cloud Dashboard, please create a free account through valid email address. Now login using newly created account and lookup/create Client ID and Client Secret at Aspose Cloud Dashboard.

Resize Image Online in Java

In this section, we are going to use GetImageFrame API to develop our TIFF picture resizer. This API request takes an image name as a path in the URL, therefore, we first need to upload the image to Cloud Storage. After updating the image parameters, the API returns the updated image in the response. You also get the capability to bulk resize photos as well as you can specify if we need to resize only a specific TIFF frame using saveOtherFrames parameter.

  • Firstly, create an object of ImagingApi based on personalized client credentials
  • Secondly, read the content of first TIFF image using readAllBytes(…) method and pass to byte[] array
  • Thirdly, create an instance of UploadFileRequest class where we specify the name of TIFF over Cloud storage
  • Now upload first TIFF image to cloud storage using uploadFile(…) method
  • Specify the TIFF frame index, new height & width for extracted Frame, and specify to only resize specified frame
  • Now create an object of GetImageFrameRequest where we specify input TIFF image and above defined properties
  • Call getImageFrame(…) method of ImagingAPI to get TIFF frame
  • Save the extracted frame to local drive using FileOutputStream object
resize tiff frame

Resize TIFF Frame Preview

The sample TIFF images used in above example can be downloaded from TiffSampleImage.tiff.

Reduce Image Size using cURL Commands

Owing to the REST architecture of API, it can also be accessed with cURL commands. So in this section, we are going to discuss the details on how to reduce image size or extract tiff frame in particular dimensions using cURL commands. Now the first step is to generate a JWT access token (based on client credentials) using following command.

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bb959721-5780-4be6-be35-ff5c3a6aa4a2&client_secret=4d84d5f6584160cbd91dba1fe145db14" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

After the JWT token generation, we need to execute following command to resize TIFF frame.

curl -v -X GET "https://api.aspose.cloud/v3.0/imaging/input.tiff/frames/0?newWidth=400&newHeight=600&saveOtherFrames=false" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>"
-o ResizedFrame.tiff

Conclusion

This article has provided some amazing detils on how to resize image (TIFF) using Java cloud SDK. We have learned the steps to resize TIFF frame using Java code snippet as well as have explored the option to resize image online using cURL commands. You may also consider testing the promising features of API is via SwaggerUI within web browser. And in case you want to modify the source code of SDK, you can download if from GitHub (all our Cloud SDKs are developed under MIT license).

Nevertheless, the Product Documentation is an amazing source of information to learn about other exciting features offered by the API Lastly, in case you encoutner any issues while using the API, you may consider approaching us for a quick resolution via free product support forum.

Please visit the following links to learn more about: