sake girman Hoto

Maimaita Hoton TIFF ta amfani da Java

Ɗaya daga cikin fitattun fasalulluka na fayilolin TIFF shine ikonsa don adana hotuna da yawa (kowanne yana da tashoshi da yawa) azaman firam ɗin jeri a cikin tari na lokaci ko z-tari na hotuna. Yanzu a cikin wannan labarin, za mu yi bayanin matakan cire firam TIFF, sake girman shi da adana shi daban akan ma’adana. Aiki na kan layi mai girman girman yana ɗaukar sabbin ƙima (nisa & tsayi) yayin adana firam ɗin TIFF da aka sabunta.

Maimaita Girman Hoto API

Aspose.Imaging Cloud SDK for Java shine tushen REST ɗinmu wanda ke ba ku damar shirya shirye-shirye, sarrafa da canza hotunan raster, Metafiles, da Photoshop zuwa nau’ikan Tsarin Tallafawa. Hakanan yana ba da fasalin don sarrafa hotunan TIFF, inda zamu iya yin aiki akan firam ɗin TIFF guda ɗaya. Yanzu, don farawa da amfani da SDK, muna buƙatar ƙara bayanin sa a cikin aikin Java. Don haka, da fatan za a ƙara cikakkun bayanai masu zuwa a cikin pom.xml na nau’in 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>

Mataki na gaba shine samun takaddun shaidar abokin ciniki daga Cloud Dashboard kuma idan baku da asusu akan Aspose Cloud Dashboard, da fatan za a ƙirƙiri asusun kyauta ta amfani da ingantaccen adireshin imel.

Mayar da Girman Hoto akan layi a Java

A cikin wannan sashe, za mu yi amfani da GetImageFrame API don haɓaka mai canza hoto na TIFF. Za mu kuma loda hoton zuwa ma’ajiyar gajimare kuma bayan sabunta sigogin hoton, ana mayar da hoton da aka gyara a cikin rafi mai amsawa. Da fatan za a lura cewa API ɗin yana ba ku damar ƙara girman hotuna ko girman takamaiman firam ɗin TIFF kawai ta amfani da siginar adanaOtherFrames.

  • Da farko, ƙirƙiri wani abu na ImagingApi ta amfani da keɓaɓɓen bayanan abokin ciniki
  • Abu na biyu, karanta abun cikin hoton TIFF na farko ta amfani da hanyar readAllBytes(…) kuma mayar da shi zuwa tsararrun byte[]
  • Na uku, ƙirƙiri misali na ajin UploadFileRequest inda muka wuce sunan hoton TIFF
  • Yanzu loda hoton TIFF na farko zuwa ma’ajiyar gajimare ta amfani da hanyar uploadFile(…).
  • Mataki na gaba shine tantance firam ɗin TIFF, sabon tsayi & girman nisa da takamaiman firam ɗin tiff.
  • Yanzu ƙirƙirar wani abu na GetImageFrameRequest inda muka wuce shigar da sunan hoton TIFF da ƙayyadaddun kaddarorin sama
  • Kira hanyar getImageFrame(…) na ajin ImagingAPI don samun ƙayyadadden firam ɗin TIFF
  • A ƙarshe, ajiye firam ɗin da aka fitar 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 TIFF na farko daga tsarin gida
File file1 = new File("TiffSampleImage.tif");
byte[] imageStream = Files.readAllBytes(file1.toPath());
			
// ƙirƙiri abin buƙatar loda fayil
UploadFileRequest uploadRequest = new UploadFileRequest("input.tiff",imageStream,null);
// loda hoton TIFF na farko zuwa ma'ajiyar gajimare
imageApi.uploadFile(uploadRequest);

Integer frameId = 0; // Frame number inside TIFF
// sabon nisa & tsayin firam ɗin da aka fitar
Integer newWidth = 400;
Integer newHeight = 600;

// Sakamakon haɗa ƙayyadadden firam kawai ba wasu firam ɗin ba
Boolean saveOtherFrames = false;

// Ƙirƙirar abin nema don fitar da firam ɗin tiff dangane da takamaiman bayanai
GetImageFrameRequest getImageFrameRequest = new GetImageFrameRequest("input.tiff", frameId, newWidth, newHeight,
                    null, null, null, null, null, saveOtherFrames, null, null);

// an dawo da firam ɗin da aka fitar a cikin rafin amsawa
byte[] updatedImage = imageApi.getImageFrame(getImageFrameRequest);

// Ajiye firam ɗin TIFF da aka fitar akan ma'ajiyar gida
FileOutputStream fos = new FileOutputStream("/Users/nayyer/Documents/" + "Extracted-TIFF.tiff");
fos.write(updatedImage);
fos.close();
sake girman tiff frame

Maimaita girman TiFF Firam ɗin Preview

Ana iya sauke samfurin TIFF hotuna da aka yi amfani da su a cikin misalin da ke sama daga TiffSampleImage.tiff.

Rage Girman Hoto ta amfani da Umarnin CURL

Sakamakon gine-ginen REST na API, ana iya samun dama ga ta ta umarnin cURL. Don haka a cikin wannan sashe, za mu tattauna cikakkun bayanai kan yadda ake rage girman hoto ko cire firam ɗin tiff tare da takamaiman girma, ta amfani da umarnin CURL. Yanzu, mataki na farko shine 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"

Bayan tsarar JWT token, muna buƙatar aiwatar da umarni mai zuwa don sake girman firam ɗin TIFF.

curl -v -X GET "https://api.aspose.cloud/v3.0/imaging/input.tiff/frames/0?newWidth=400&newHeight=600&saveOtherFrames=false" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>"
-o ResizedFrame.tiff

Kammalawa

Wannan labarin ya ba da cikakkun bayanai masu sauƙi amma ban mamaki kan yadda ake sake girman hoto (TIFF) ta amfani da Java. Wannan koyawa ta kuma bayyana duk matakan da za a sake girman firam ɗin TIFF ta amfani da umarnin CURL. Lura cewa wani zaɓi don gwada iyawar API ta hanyar SwaggerUI a cikin mai binciken gidan yanar gizo. Hakanan, idan kuna sha’awar canza lambar tushe na SDK, ana iya saukar da ita daga GitHub, kamar yadda ake buga shi ƙarƙashin lasisin MIT.

Koyaya, Takardun Samfura tushen bayanai ne mai ban mamaki don koyan duk cikakkun bayanai masu mahimmanci game da sauran abubuwan ban sha’awa na API. A ƙarshe, idan kun haɗu da batutuwa 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: