Kompres JPG ing Node SDK

Ngurangi ukuran JPG nggunakake JavaScript

Nggunakake REST API ing JavaScript, pangembang bisa ngompres JPG kanthi program. Kanthi solusi sing diwenehake, output bakal dadi file berkualitas tinggi sawise kompresi.

Ndeleng potongan kode

Compress JPG ing JavaScript

Nggunakake JavaScript API sing kuat, pangembang bisa ngompres JPG kanggo ngoptimalake isi lan ukuran file output. Ngurangi ukuran file dumadi kanthi ngresiki data lan sumber daya sing ora digunakake. Sampeyan uga bisa compress gambar kanggo nggawe ukuran file output malah luwih cilik.

Asil optimasi lan kompresi isi bisa disimpen ing JPG asli utawa format nyimpen sing kasedhiya - DOCX, DOC, RTF, PDF, HTML lan liya-liyane.

Ngurangi ukuran JPG file ing JavaScript

Kaya sing wis kasebut, SDK Node kita ngidini sampeyan nyuda ukuran JPG kanthi program. Lan saiki sampeyan bisa nyoba fungsi sing kuat lan ngevaluasi cara ngompres JPG ing JavaScript kanthi conto ing ngisor iki:

Unggah file sing pengin dioptimalake / kompres
Kode roto
Pilih format target saka dhaptar
import * as fs from "fs";

const wordsApi = new WordsApi("####-####-####-####-####", "##################");

const requestDocument = fs.createReadStream("Input.jpg");
const requestCompressOptions = new model.CompressOptions({
    imagesQuality: 75,
    imagesReduceSizeFactor: 1
})
const compressDocumentRequest = new model.CompressDocumentOnlineRequest({
    document: requestDocument,
    compressOptions: requestCompressOptions
});

wordsApi.compressDocumentOnline(compressDocumentRequest)
.then((compressDocumentResult) => {
    const requestDocument = compressDocumentResult.Document.Values();
    const convertDocument = new model.ConvertDocumentRequest({
        document: requestDocument,
        format: "jpg"
    });

    wordsApi.convertDocument(convertDocument)
    .then((convertDocumentResult) => {
        console.log("Result of ConvertDocument: ", convertDocumentResult);
    });
});
Kode roto
  
Nyalin kode JavaScript menyang clipboard

Carane ngompres JPG ing JavaScript

  1. Pasang Aspose.Words Cloud for Node
  2. Tambah referensi perpustakaan (ngimpor perpustakaan) menyang proyek JavaScript sampeyan
  3. Konfigurasi API nggunakake tombol app
  4. Muat sumber JPG kanggo ngompres
  5. Kompres JPG, ngresiki informasi sing ora digunakake
  6. Pilih format file output
  7. Entuk asil kompresi JPG minangka file sing kapisah

Pustaka JavaScript kanggo nggunakake kompresi JPG.

Instal 'Aspose.Words Cloud SDK for Node.js' nggunakake manajer paket NPM. npm install asposewordscloud --save saka baris perintah kanggo nginstal SDK liwat manajer paket NPM. Minangka alternatif, sampeyan bisa kanthi manual kloning Aspose.Words Cloud SDK for Node.js saka GitHub lan nggunakake ing project. Tututi Instructions iki supaya cepet entuk kredensial keamanan sing dibutuhake lan ngakses REST API kita.

Requirements Sistem

  • @types/request (version 2.48.3+)
  • lodash (version 4.17.15+)
  • lodash.template (version 4.5.0+)
  • request (version 2.88.0+)
  • request-debug (version 0.2.0+)

Deleng Repository Documentation kanggo ndeleng rincian liyane.

Format file liyane sing didhukung

Sampeyan bisa nindakake kompresi dokumen kanggo format file liyane:

5%

Langganan kanggo Aspose Update Product

Entuk buletin saben wulan lan tawaran langsung dikirim menyang kothak layang.

© Aspose Pty Ltd 2001-2024. Kabeh hak dilindhungi undhang-undhang.