how to extract tiff image

How to extract images from TIFF files

TIFF of TIF is an abbreviation for Tag Image File Format and its among the popular raster graphics images, widely used by graphic artists, the publishing industry, and photographers. The TIFF is different from JPEG, GIF, and PNG because it is an “uncompressed” format and can store much more image data than their JPEG counterparts. Now 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, we are going to explore the details on how to extract frames from multi-frame TIFF images using Java Cloud SDK.

TIFF Image Processing API

We have created an image processing API offering the capabilities to edit, manipulate and transform raster, metafiles, photoshop and other Supported Formats to a variety of file formats. Now talking about TIFF image manipulation, the API is very much capable of processing TIFF images. So as per the scope of this article, we are going to use Aspose.Imaging Cloud SDK for Java which is a wrapper around REST API. So the first step in utilizing its capabilities is to add its reference in 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.

How to Extract TIFF Image in Java

Let’s explore the details on how to extract images from tiff files using Java code snippet. Please note that the API also lets you resize, crop and rotateFlip the extracted frame. Moreover, one of the boolean parameter saveOtherFrames let you specify whether the result will include all other frames or just a specified frame.

  • 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
  • Next step is to specify the TIFF frame index, height & width of extracted Frame, origin of extraction and specify if you want the extracted frame in particular angel
  • 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
extract tiff frame

Get TIFF Frames Preview

The sample TIFF images used in above example can be downloaded from DeskewSampleImage.tif.

TIFF Image Processing using cURL Commands

Another convenient way of accessing REST APIs is via cURL commands. Since Aspose.Imaging Cloud is based on REST architecture, so we can also extract tiff images frames using cURL commands. Now the pre-requisite of this activity 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 extract TIFF images frame.

curl -v -X GET "https://api.aspose.cloud/v3.0/imaging/first.tiff/frames/0?newWidth=1000&newHeight=1200&x=10&y=10&rectWidth=800&rectHeight=800&saveOtherFrames=false" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-o ExtractedFrame.tiff

Conclusion

At this point, we have learned all the necessary details on how to extract images from tiff files. We have explored the option to extract TIFF frame using Java Java code snippet or through cURL commands. Another approach to test the promising features of API is via SwaggerUI 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: