webp menyang jpg

Ngonversi Webp menyang JPEG ing Jawa

WebP minangka format gambar modern sing populer nyedhiyakake kompresi lossless lan lossy sing unggul kanggo gambar ing web. Format gambar iki dikembangake dening Google lan dimaksudake minangka panggantos kanggo format file JPEG, PNG, lan GIF. Ndhukung kompresi lossy lan lossless, uga animasi lan transparansi alpha. Iki uga populer amarga file WebP umume luwih cilik tinimbang JPEG tradisional lan mula situs web mbukak luwih cepet lan menehi pengalaman sing luwih apik kanggo pangguna. Nanging, akeh sistem konvensional isih mbutuhake format gambar raster kanggo tujuan panyimpenan lan pangolahan, mula, kita duwe syarat kanggo nindakake konversi akeh WebP menyang JPG. Dadi ing artikel iki, kita bakal ngrembug rincian babagan cara ngowahi format WebP dadi JPG, WebP dadi PNG lan WebP dadi GIF.

WebP menyang JPG REST API

Solusi basis REST kita Aspose.Imaging Cloud SDK for Java minangka API pangolahan gambar lan konversi gambar sing dipercaya. Kanthi bantuan saka API iki, sampeyan bisa ngleksanakake kemampuan pangolahan gambar (ngowahi lan ngowahi) ing aplikasi sampeyan. Ndhukung gambar raster, file Photoshop, Metafiles lan format liyane kayata format WebP. Dadi miturut ruang lingkup artikel iki, kita bakal nggunakake API iki kanggo ngowahi WebP dadi JPEG. Saiki kanggo miwiti nggunakake SDK, kita kudu nambah referensi ing proyek java kita kanthi nyakup informasi ing pom.xml (proyek jinis mbangun maven).

<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>22.4</version>
    </dependency>
</dependencies>

Sawise referensi REST API wis ditambahake ing proyek Java, entuk kredensial klien saka Cloud Dashboard. Yen ora, sampeyan kudu ndhaptar akun gratis nalika nggunakake alamat email sing bener.

Ngonversi WebP menyang JPEG ing Jawa

Ayo kita rembugan rincian babagan carane mbukak lan ngowahi WebP menyang format JPG nggunakake potongan kode Java.

  • Kaping pisanan, nggawe obyek ImagingApi nggunakake kredensial pribadi
  • Kapindho, muat gambar WebP nggunakake metode readAllBytes(…) lan pass menyang array byte[]
  • Katelu, gawe conto UploadFileRequest kanthi nyedhiyakake gambar WebP minangka argumen lan upload menyang panyimpenan maya nggunakake metode uploadFile(…)
  • Saiki gawe obyek ConvertImageRequest sing njupuk jeneng gambar WebP lan format JPG minangka argumen
  • Telpon metode convertImage(…) kanggo ngowahi WebP dadi format JPEG. Output bali minangka stream respon
  • Pungkasan, simpen asil JPG menyang drive lokal nggunakake obyek FileOutputStream
// Entuk ClientID lan ClientSecret saka https://dashboard.aspose.cloud/
String clientId = "bb959721-5780-4be6-be35-ff5c3a6aa4a2";
String clientSecret = "4d84d5f6584160cbd91dba1fe145db14";

// nggawe obyek Imaging
ImagingApi imageApi = new ImagingApi(clientSecret, clientId);

// mbukak gambar WebP saka drive lokal
File file1 = new File("WEBPSampleImage.webp");
byte[] imageStream = Files.readAllBytes(file1.toPath());
			
// nggawe obyek panjalukan upload file
UploadFileRequest uploadRequest = new UploadFileRequest("source.webp",imageStream,null);
// upload gambar WebP menyang panyimpenan Cloud
imageApi.uploadFile(uploadRequest);

// nemtokake format output minangka JPEG
String format = "jpg";

// Nggawe obyek panjalukan konversi Gambar
ConvertImageRequest convertImage = new ConvertImageRequest("source.webp", format, null, null);
// Ngonversi WebP kanggo JPEG lan ngasilake output ing stream respon
byte[] resultantImage = imageApi.convertImage(convertImage);

// Simpen asil JPG menyang drive lokal
FileOutputStream fos = new FileOutputStream("/Users/nayyer/Documents/" + "Converted.jpg");
fos.write(resultantImage);
fos.close();

Gambar WebP sampel sing digunakake ing conto ing ndhuwur bisa diundhuh saka WEBPSampleImage.webp lan output saka Converted.jpg.

webp menyang jpg

Gambar: - Pratinjau konversi WebP dadi JPG

WebP menyang PNG ing Jawa

Bagean iki mbahas rincian babagan carane ngowahi WebP menyang format PNG tanpa nggunakake panyimpenan Cloud.

  • Pisanan, gawe obyek ImagingApi nggunakake kredensial pribadi
  • Kapindho, muat gambar WebP nggunakake metode readAllBytes(…) lan pass menyang array byte[]
  • Katelu, nggawe obyek CreateConvertedImageRequest sing njupuk jeneng gambar WebP lan format PNG minangka argumen.
  • Saiki nelpon metode createConvertedImage(…) kanggo ngowahi WebP dadi PNG. Output bali minangka stream respon
  • Pungkasan, simpen asil PNG menyang drive lokal nggunakake objek FileOutputStream
// Entuk ClientID lan ClientSecret saka https://dashboard.aspose.cloud/
String clientId = "bb959721-5780-4be6-be35-ff5c3a6aa4a2";
String clientSecret = "4d84d5f6584160cbd91dba1fe145db14";

// nggawe obyek Imaging
ImagingApi imageApi = new ImagingApi(clientSecret, clientId);

// mbukak gambar WebP saka drive lokal
File file1 = new File("WEBPSampleImage.webp");
byte[] imageStream = Files.readAllBytes(file1.toPath());
			
// nemtokake format output minangka PNG
String format = "png";

// Nggawe obyek panjalukan konversi Gambar
CreateConvertedImageRequest convertRequest = new CreateConvertedImageRequest(imageStream,format,null,null);
// Ngonversi WebP menyang PNG lan ngasilake output ing stream respon
byte[] resultantImage = imageApi.createConvertedImage(convertRequest);

// Simpen asil PNG menyang drive lokal
FileOutputStream fos = new FileOutputStream("/Users/nayyer/Documents/" + "Converted.png");
fos.write(resultantImage);
fos.close();

Cathetan: - Yen kita kudu nyimpen PNG asil ing panyimpenan maya, pass rincian path PNG nalika nggawe obyek CreateConvertedImageRequest. Ing pendekatan iki, langkah pungkasan kanggo nyimpen stream output menyang drive lokal bakal dilewati.

WebP menyang GIF nggunakake CURL Commands

API REST uga bisa diakses liwat perintah cURL, mula ing bagean iki, kita bakal nindakake konversi WebP menyang GIF nggunakake perintah cURL. Saiki prasyarat kanggo ngasilake token akses JWT (adhedhasar kredensial klien) nggunakake printah ing ngisor iki.

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"

Sawise JWT wis digawe, bukak printah ing ngisor iki kanggo nindakake konversi WebP menyang GIF.

curl -v -X GET "https://api.aspose.cloud/v3.0/imaging/WEBPSampleImage.webp/convert?format=GIF" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-o "Converted,gif"

Kesimpulan

Artikel iki wis nerangake kabeh rincian sing perlu babagan carane ngowahi WebP dadi JPEG, WebP dadi PNG lan carane nindakake konversi WebP dadi GIF nggunakake REST API. Kita wis sinau langkah-langkah kanggo ngowahi WebP dadi JPG kanthi program utawa ngowahi webp dadi gif nggunakake perintah cURL. Kita banget ngajak sampeyan njelajah Dokumentasi Produk sing dadi sumber informasi sing apik tenan kanggo sinau babagan fitur-fitur menarik liyane sing ditawakake API.

Sampeyan uga bisa nimbang nguji fitur API liwat SwaggerUI ing browser web lan yen sampeyan kudu ngundhuh lan ngowahi kode sumber Cloud SDK, kasedhiya ing GitHub (diterbitake ing lisensi MIT) . Pungkasan, yen sampeyan ngalami masalah nalika nggunakake API, sampeyan bisa uga nimbang nyedhaki kita kanggo resolusi cepet liwat [forum dhukungan produk] gratis 9.

Artikel sing gegandhengan

Mangga bukak link ing ngisor iki kanggo mangerteni sing luwih lengkap babagan: