resize Image

Resize TIFF Image using Java

One of the prominent features of TIFF files is its capabilities to store multiple images (each having multiple channels) as sequential frames in a time-stack or z-stack of images. Now in this article, we are going to explain the steps to extract a TIFF frame, resize it and save it separately on a storage. The resize image online operation caters to new dimensions (width & height) while saving the updated TIFF Frame.

Resize Image API

Aspose.Imaging Cloud SDK for Java is our REST based solution enabling you to programmatically edit, manipulate and transform raster images, Metafiles, and Photoshop to a variety of Supported Formats. It also offers the feature to manipulate TIFF images, where we can even work on individual TIFF frames. Now, in order to get started with the SDK utilization, we need to add its reference in a Java project. So, please add the following details in pom.xml of 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 the client credentials from Cloud Dashboard and if you do not have an account over Aspose Cloud Dashboard, please create a free account using valid email address.

Resize Image Online in Java

In this section, we are going to use GetImageFrame API to develop our TIFF picture resizer. We will also upload the image to cloud storage and after updating the image parameters, the modified image is returned in response stream. Please note that the API enables you to bulk resize photos or resize only a specific TIFF frame using saveOtherFrames parameter.

  • Firstly, create an object of ImagingApi using personalized client credentials
  • Secondly, read the content of first TIFF image using readAllBytes(…) method and return it to byte[] array
  • Thirdly, create an instance of UploadFileRequest class where we pass the name of TIFF image
  • Now upload the first TIFF image to cloud storage using uploadFile(…) method
  • The next step is to specify the TIFF frame index, new height & width dimensions and particular tiff frame index
  • Now create an object of GetImageFrameRequest where we pass the input TIFF image name and above defined properties
  • Call the getImageFrame(…) method of ImagingAPI class to obtain the specified TIFF frame
  • Finally, save the extracted frame to local drive using FileOutputStream object
resize tiff frame

Resize TIFF Frame Preview

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

Reduce Image Size using cURL Commands

Owing to the REST architecture of the API, it can also be accessed via cURL commands. So in this section, we are going to discuss the details on how to reduce image size or extract tiff frame with particular dimensions, using the cURL commands. Now, the first step is to generate a JWT access token (based on client credentials) using the 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 the following command to resize the 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 simple but amazing details on how to resize image (TIFF) using Java. This tutorial has also explained all the steps to resize TIFF frame using cURL commands. Please note that another option to test the API capabilities is via SwaggerUI within a web browser. Also, if you are interested to modify the source code of the SDK, it can be downloaded from GitHub, as it’s published under MIT license.

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

Please visit the following links to learn more about: