turn png to jpg

Change PNG to JPG using Java Cloud SDK

PNG images excel in supporting transparent backgrounds and high-quality visuals. However, the file sizes tend to be larger, which can impact storage and loading speeds, especially on web platforms. JPG, on the other hand, offers efficient compression that reduces file size without significantly compromising image quality. Therefore, by converting PNG images to JPG, you can maintain essential image clarity while achieving faster load times and broader format compatibility, which is beneficial for both user experience and system performance.

Image Processing API

By using the Aspose.Imaging Cloud SDK for Java, the action to transfer PNG to JPG format is straightforward and efficient, making it ideal for developers looking to optimize image workflows. By leveraging this API, you can automate image conversions in your Java applications with minimal effort and streamline image processing. Furthermore, it reduces file sizes, enhances compatibility across platforms, especially in applications where fast loading and efficient storage are critical.

Add the API reference in java project by including the following information in pom.xml of maven build type project.

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

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

Once the JDK reference has been added in project, the next important step is to create a free account over Aspose cloud dashboard. Simply sign up for a Free Trial through a valid email address. Now login using newly created account and lookup/create Client ID and Client Secret at Cloud dashboard.

Convert PNG to JPG using Java

Let’s discuss the details on how we can transfer PNG to JPG using Java code snippet.

ImagingApi imageApi = new ImagingApi(clientSecret, clientId);

Create an instance of ImagingApi based on personalized client credentials.

File file1 = new File("C:\\Users\\nayyer\\input.png");
byte[] imageStream = Files.readAllBytes(file1.toPath());

Read the input PNG image into byte array.

imageApi.uploadFile(uploadRequest);

Upload the input PNG image to the cloud storage.

ConvertImageRequest convertImage = new ConvertImageRequest("input.png", "jpg", null, null);

Create an object of ConvertImageRequest class where we specify the output format as JPG.

byte[] resultantImage = imageApi.convertImage(convertImage);

Finally, call the API to convert the PNG to JPEG format. After the conversion, the resultant JPEG image is returned in byte array.

Turn PNG to JPG using cURL Commands

Converting PNG to JPG using Aspose.Imaging Cloud and cURL commands offers a quick and effective way to handle image transformations directly from the command line. This method is highly flexible and can be incorporated into automated scripts or workflows, enabling seamless image processing without the need for complex software setups.

Firstly, generate a JWT access token (based on client credentials) while executing the following command:

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

Once the JWT access token has been generated, please call CreateConvertedImage API to transform PNG to JPEG format. In order to save the resultant file on local drive, please use -o argument.

curl -v "https://api.aspose.cloud/v3.0/imaging/{sourceFile}/convert?format=tiff" \
-X GET \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}"
- o "myResultant"

Replace sourceFile with the name of input PNG image available in cloud storage, myResultant with the name of resultant JPEG image and accessToken with the name of bearer token generated above.

Free PNG to JPG Converter

To witness the amazing capabilities of Aspose.Imaging Cloud SDK, you may consider using our lightweight and super efficient PNG to JPG converter App. This application is built on top of REST API, and can easily be accessed within a web browser.

png to jpg

A preview of PNG to JPG Converter App.

Conclusion

In conclusion, converting PNG to JPG using the Aspose.Imaging Cloud SDK for Java provides a powerful, flexible solution for handling image formats efficiently. Whether using the SDK or cURL commands, Aspose.Imaging ensures reliable and high-performance image conversion, fitting seamlessly into various development environments.

We highly recommend visiting the following links to learn more about: