PSD galibi masu zanen kaya da masu fasaha ne ke amfani da fayiloli, kamar yadda takaddun Photoshop sune mafi ƙarfi don ƙirƙirar bayanan hoto da adanawa. Sigar asali ce ta Adobe Photoshop kuma ana iya kallo a cikin Adobe Illustrator ko Inkscape. Koyaya, yawancin masu amfani ba su da irin waɗannan aikace-aikacen kasuwanci na asali. Hakanan, ba za mu iya nuna fayilolin PSD a cikin mai binciken gidan yanar gizo ba. Don haka wannan labarin, zai bayyana cikakkun bayanai kan Yadda Ake Duba Fayilolin PSD Ba tare da Photoshop akan Wayar hannu ko PC ta hanyar canza PSD zuwa JPG akan layi ba.
- API ɗin Canjin PSD zuwa JPG
- Maida PSD zuwa JPG a Java
- Maida Photoshop zuwa JPG ta amfani da Umarnin CURL
API ɗin Canjin PSD zuwa JPG
Yanzu don musanya PSD zuwa JPG, za mu yi amfani da Aspose.Imaging Cloud SDK for Java wanda ke ba mu damar aiwatar da ikon sarrafa hoto da juzu’i a aikace-aikacen Java. Don haka za mu iya shirya da tsari, sarrafa da canza hotunan raster, Metafiles & Fayilolin Photoshop zuwa nau’ikan Tsarin Tallafi. Yanzu don farawa da amfani da SDK, muna buƙatar mu fara ƙara bayanin sa a cikin aikin java ɗinmu ta hanyar haɗa bayanai masu zuwa a cikin pom.xml na ginin ginin 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>
Idan an riga an yi rajista akan Aspose Cloud Dashboard, da fatan za a sami keɓaɓɓen bayanan abokin ciniki daga Cloud Dashboard. In ba haka ba, yi rijistar asusu kyauta ta amfani da ingantaccen adireshin imel sannan sami takaddun shaidar ku.
Maida PSD zuwa JPG a Java
A cikin wannan sashe, za mu tattauna cikakkun bayanai kan yadda ake canza PDF zuwa JPG akan layi ta amfani da snippet code na Java.
- Da farko, ƙirƙiri wani abu na aji na ImagingApi ta hanyar ƙaddamar da keɓaɓɓen bayanan abokin ciniki a matsayin hujja ga maginin sa.
- Na biyu, karanta shigar da fayil ɗin PSD ta amfani da hanyar readAllBytes(…) kuma mayar da abun ciki zuwa tsararrun byte[]
- Na uku, ƙirƙiri misali na ajin UploadFileRequest sannan loda fayil ɗin PSD zuwa ma’ajiyar gajimare ta amfani da hanyar uploadFile(…)
- Yanzu ƙirƙiri wani abu na ConvertImageRequest class inda muka saka sunan PSD mai shigar da sakamakon da aka samu a matsayin “jpg”
- A ƙarshe, kira hanyar da za ta canzaImage(…) don canza PSD zuwa hoton JPG. Ana mayar da hoton sakamakon a cikin rafin martani
- A ƙarshe, ajiye sakamakon JPG 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);
// loda hoton PSD daga tsarin gida
File file1 = new File("FilterEffectSampleImage.psd");
byte[] imageStream = Files.readAllBytes(file1.toPath());
// ƙirƙiri abin buƙatar loda fayil
UploadFileRequest uploadRequest = new UploadFileRequest("source.psd",imageStream,null);
// loda fayil ɗin PSD zuwa ma'ajiyar Cloud
imageApi.uploadFile(uploadRequest);
// saka da fitarwa format na hoto
String format = "jpg";
// Ƙirƙiri abin buƙatar canza hoto
ConvertImageRequest convertImage = new ConvertImageRequest("source.psd", format, null, null);
// canza PSD zuwa JPG kuma mayar da hoto a cikin rafi mai amsawa
byte[] resultantImage = imageApi.convertImage(convertImage);
// Ajiye sakamako na JPG zuwa ma'ajiyar gida
FileOutputStream fos = new FileOutputStream("/Users/nayyer/Documents/" + "Converted.jpg");
fos.write(resultantImage);
fos.close();
Hoton PSD da aka yi amfani da shi a sama misali ana iya sauke shi daga FilterEffectSampleImage.psd.
Maida Photoshop zuwa JPG ta amfani da Umarnin CURL
Kamar yadda Aspose.Imaging Cloud ya haɓaka bisa ga tsarin gine-gine na REST, don haka za mu iya samun damar API cikin sauƙi ta hanyar umarnin cURL ta hanyar layin umarni (a kan kowane dandamali). Yanzu a matsayin abin da ake buƙata, muna buƙatar fara 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"
Da zarar an ƙirƙiri alamar JWT, da fatan za a aiwatar da umarni mai zuwa don canza Photoshop zuwa tsarin JPG.
curl -v -X GET "https://api.aspose.cloud/v3.0/imaging/source.psd/convert?format=jpg" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>" \
-o Resultant.jpg
Kammalawa
Wannan labarin ya haskaka mana a kan ban mamaki alama ga tana mayar PSD zuwa JPG ta amfani da Java. A lokaci guda, mun kuma bincika Photoshop adana azaman hanyar JPEG ta amfani da umarnin CURL. Bugu da ƙari, ana iya gwada fasalulluka na API ɗin cikin sauƙi ta amfani da SwaggerUI (a cikin mai binciken gidan yanar gizo) kuma ana iya saukar da cikakkiyar lambar tushen SDK daga GitHub (an buga ƙarƙashin lasisin MIT).
Duk da haka, Takardun Samfura tushen bayanai ne mai ban mamaki don koyan wasu abubuwan ban sha’awa na API. A ƙarshe, idan kun ci karo da kowace matsala ko kuna da wata tambaya mai alaƙa, da fatan za ku ji daɗin tuntuɓar mu don ƙuduri mai sauri ta hanyar Tallafin tallafin samfur.
Labarai masu alaka
Da fatan za a ziyarci hanyoyin haɗin yanar gizon don ƙarin koyo game da: