이 단계별 자습서에서는 Java REST API를 사용하여 GIF를 JPG로 변환하는 방법을 보여줍니다. GIF(Graphics Interchange Format) 파일은 픽셀당 최대 8비트를 지원하고 무손실 압축 기술을 사용하는 이미지 파일입니다. 웹 그래픽 및 애니메이션 배너에 일반적으로 사용되며 투명한 배경을 지원합니다.
그러나 JPG(또는 JPEG)는 디지털 사진 및 기타 유형의 래스터 그래픽에 사용되는 널리 사용되는 이미지 파일 형식입니다. Joint Photographic Experts Group의 약자로 디지털 이미지의 크기를 줄이는 데 사용되는 손실 압축 기술입니다. JPG 파일은 일반적으로 다른 이미지 파일 유형보다 작기 때문에 웹에서 많이 사용됩니다. Java Low Code API에서 GIF를 JPG로 변환해야 하는 경우 아래 코드를 사용하여 수행할 수 있습니다.
필수 조건
- 계정 생성 및 API 자격 증명 얻기
- Aspose.Imaging Cloud SDK for Java 다운로드
- 위의 SDK로 Java 프로젝트 설정
Java REST API에서 GIF를 JPG로 변환하는 단계
- API에 대한 클라이언트 ID 및 클라이언트 암호 설정
- 클라이언트 자격 증명으로 ImagingAPI 클래스의 객체 생성
- 입력 및 출력 파일 지정
- 입력된 GIF 파일을 읽고 클라우드 스토리지에 업로드
- 입력 및 출력 파일 형식으로 ConvertImageRequest 객체 생성
- convertImage 메서드를 호출하여 REST API를 사용하여 GIF를 JPG로 변환
- 출력 JPG 파일을 로컬 디스크에 저장
Java Low Code API에서 GIF를 JPG로 변환하는 코드
String ClientID = Client.getID(); //replace Client.getID() with your own client ID here | |
String ClientSecret = Client.getSecret(); //replace Client.getSecret() with your own client secret here | |
String APIBaseUrl="https://api.aspose.cloud"; | |
String Local_Path = "C:/Temp/"; | |
ImagingApi imagingApiSdk = new ImagingApi(ClientSecret, ClientID, APIBaseUrl); | |
// Input & output file names | |
String inputFileName = "GIFtoJPG.gif"; | |
String outputFileName = "GIFtoJPG.jpg"; | |
try { | |
// Upload local image to Cloud Storage | |
File inputFile = new File(Local_Path + inputFileName); | |
FileInputStream inputFileStream = new FileInputStream(inputFile); | |
byte[] inputImageData = IOUtils.toByteArray(inputFileStream); | |
UploadFileRequest uploadFileRequest = new UploadFileRequest(inputFileName, inputImageData, null); | |
FilesUploadResult filesUploadResult = imagingApiSdk.uploadFile(uploadFileRequest); | |
String outputFormat = "jpg"; | |
String remoteFolder = null; // Input file is saved at the root of the storage | |
String remoteStorage = null; // Cloud Storage name | |
ConvertImageRequest convertImageRequest = new ConvertImageRequest(inputFileName, outputFormat, remoteFolder, remoteStorage); | |
byte[] convertedImageData = imagingApiSdk.convertImage(convertImageRequest); | |
// Save exported image to local storage | |
FileOutputStream fileOutputStream = new FileOutputStream(Local_Path + outputFileName); | |
fileOutputStream.write(convertedImageData); | |
fileOutputStream.close(); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} |
위에 표시된 코드를 사용하면 Java REST API를 사용하여 GIF를 JPG로 변환할 수 있습니다. Aspose.Imaging REST API SDK의 도움으로 GIF 파일을 제공하고 출력 JPG 파일을 다운로드하여 로컬에 저장하기만 하면 됩니다.
이 GIF를 JPG로 변환하는 기능은 Windows, Linux 또는 Mac에서 코드가 없거나 코드가 적은 앱에서 실행할 수 있습니다.
다음 항목에서 유사한 기능을 찾을 수 있습니다. Java REST API를 사용하여 EMF를 PDF로 변환하는 방법