PNG zuwa PSD

Maida PNG zuwa PSD akan layi a Java

Zane mai ɗaukar hoto na hanyar sadarwa (PNG) nau’in hoto ne na raster dangane da tsarin bitmap kuma ana amfani da shi sosai akan gidajen yanar gizo don nuna hotuna na dijital masu inganci. Wannan tsarin ya shahara saboda yana ba da matsi mara asara da palette mai faɗi da haske. Koyaya, idan aka zo batun gyaran hoto, yana da kusan ba zai yuwu a gyara abubuwan da ke cikin hoton PNG ba. Amma, idan muna da fayil PSD (tsarin Adobe Photoshop tsoho), abu ne mai sauƙi don shirya irin waɗannan hotuna. Don haka a cikin wannan labarin, za mu tattauna duk cikakkun bayanai kan yadda ake canza PNG zuwa PSD akan Wayar hannu ko PC ta amfani da REST API.

API ɗin Canjin PSD zuwa PNG

Domin canza hoto ɗaya zuwa wani tsari na tsari, Aspose.Imaging Cloud SDK for Java mafita ce mai ban mamaki. Kuna samun zaɓi don shiryawa da tsari, sarrafa da canza hotunan raster, Metafiles da fayilolin Photoshop zuwa nau’ikan tsararrun tallafi masu goyan baya. Wannan SDK guda ɗaya yana da ikon juyar da PNG zuwa PSD kuma akasin haka. Don haka tare da ƙananan layukan lambobi, zaku iya yin sauƙin PNG zuwa fassarar PSD.

Yanzu, don farawa da amfani da SDK, muna buƙatar ƙara bayaninsa a cikin aikin Java ta haɗa da bin bayanai a cikin pom.xml (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>22.4</version>
    </dependency>
</dependencies>

Idan kun riga kun yi rajista akan Aspose Cloud, da fatan za a sami takaddun shaidar abokin ciniki daga Dashboard. In ba haka ba, kuna buƙatar fara rajistar asusun kyauta ta amfani da adireshin imel mai aiki.

Canza PNG zuwa PSD a Java

Wannan sashe yana bayyana cikakkun bayanai na yadda ake canza PNG zuwa PSD ta amfani da snippet code na Java.

  • Da farko, ƙirƙiri wani abu na ImagingApi yayin ƙaddamar da keɓaɓɓen bayanan abokin ciniki.
  • Na biyu, loda fayil ɗin PNG ta amfani da hanyar readAllBytes(…) kuma mayar da ƙima zuwa byte[] tsararru.
  • Na uku, ƙirƙiri misali na UploadFileRequest yayin wucewa sunan PNG azaman gardama kuma loda shi zuwa ma’ajiyar girgije ta amfani da hanyar uploadFile(…).
  • Yanzu ƙirƙiri wani abu na ConvertImageRequest wanda ke ɗaukar shigar da sunan PNG da tsarin sakamako (PSD) azaman muhawara.
  • Kira hanyar maidaImage(…) don canza tsarin PNG zuwa tsarin PSD kuma dawo da fitarwa azaman rafin amsawa.
  • A ƙarshe, adana sakamakon PSD zuwa faifan gida ta amfani da abu FileOutputStream.
// Samu ClientID da ClientSecret daga https://dashboard.aspose.cloud/
String clientId = "7ef10407-c1b7-43bd-9603-5ea9c6db83cd";
String clientSecret = "ba7cc4dc0c0478d7b508dd8ffa029845";

// haifar da Hoto abu
ImagingApi imageApi = new ImagingApi(clientSecret, clientId);

// zazzage hoton png daga faifan gida
File file1 = new File("input.png");
byte[] imageStream = Files.readAllBytes(file1.toPath());
			
// ƙirƙiri abin buƙatar loda fayil
UploadFileRequest uploadRequest = new UploadFileRequest("input.png",imageStream,null);
// loda hoton PNG zuwa ma'ajiyar gajimare
imageApi.uploadFile(uploadRequest);

// saka da fitarwa format na hoto
String format = "psd";

// Ƙirƙiri abin buƙatar canza hoto
ConvertImageRequest convertImage = new ConvertImageRequest("input.png", format, null, null);
// canza PNG zuwa PSD kuma mayar da hoto a cikin rafin amsawa
byte[] resultantImage = imageApi.convertImage(convertImage);

// Ajiye sakamakon PSD zuwa faifan gida
FileOutputStream fos = new FileOutputStream("/Users/nayyer/Documents/" + "Converted.psd");
fos.write(resultantImage);
fos.close();

Hoton PNG da fayil ɗin PSD da aka yi amfani da su a cikin misalin da ke sama za a iya sauke su daga PinClipart.png da Converted.psd, bi da bi.

png zuwa psd

Hoto: - PNG zuwa samfoti na juyawa PSD

PNG zuwa PSD ta amfani da Umarnin CURL

Ana iya samun dama ga REST APIs cikin sauƙi ta hanyar umarnin cURL (ta tashar layin umarni). Don haka a cikin wannan sashe, za mu bincika cikakkun bayanai na yadda ake yin PNG zuwa canjin PSD ta amfani da umarnin cURL. Yanzu, a matsayin abin da ake buƙata, muna buƙatar samar da alamar samun damar JWT (bisa ga shaidar abokin ciniki) ta amfani da umarni mai zuwa.

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"

Yanzu da fatan za a aiwatar da umarni mai zuwa don sauya tsarin PNG zuwa tsarin PSD kuma adana abin fitarwa akan tuƙi na gida.

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

Kammalawa

A ƙarshen wannan labarin, mun bincika duk cikakkun bayanai na yadda za mu iya canza PNG zuwa PSD ta amfani da Java REST API. Hakazalika, mun kuma bincika wani zaɓi don canza PNG zuwa PSD ta amfani da umarnin CURL. Banda waɗannan hanyoyin, ana iya gwada fasalin API ɗin cikin sauƙi ta amfani da SwaggerUI (a cikin mai binciken gidan yanar gizo). Bugu da ƙari, cikakken lambar tushe na SDK yana samuwa akan GitHub (an buga shi ƙarƙashin lasisin MIT). Kuna iya yin la’akari da zazzagewa da gyara shi gwargwadon buƙatunku.

Duk da haka, takardun samfur tushen bayanai ne mai ban mamaki don koyo da bincika sauran abubuwan ban sha’awa, wanda API ɗin ke bayarwa. A ƙarshe, idan kun haɗu da kowace matsala yayin amfani da API, kuna iya la’akari da kusantar mu don ƙuduri mai sauri ta hanyar dandalin tallafin samfur 9.

Labarai masu alaka

Da fatan za a ziyarci hanyoyin haɗin yanar gizon don ƙarin koyo game da: