Google berkomitmen untuk mendorong terwujudnya keadilan ras bagi komunitas Kulit Hitam. Lihat caranya.

Mengubah Ukuran Gambar

Firebase
Made by Firebase

Mengubah ukuran gambar yang diupload ke Cloud Storage ke ukuran yang ditentukan, dan (jika diinginkan) mempertahankan atau menghapus gambar aslinya.

Cara kerja ekstensi ini

Use this extension to create resized versions of an image uploaded to a Cloud Storage bucket.

When you upload a file to your specified Cloud Storage bucket, this extension:

  • Detects if the file is an image. If it is, then:
  • Creates a resized image with your specified dimensions.
  • Names the resized image using the same name as the original uploaded image, but suffixed with your specified width and height.
  • Stores the resized image in the same Storage bucket as the original uploaded image.

You can even configure the extension to create resized images of different dimensions for each original image upload. For example, you might want images that are 200x200, 400x400, and 680x680 - this extension can create these three resized images then store them in your bucket.

The extension automatically copies the following metadata, if present, from the original image to the resized image(s): Cache-Control, Content-Disposition, Content-Encoding, Content-Language, Content-Type, and user-provided metadata (a new Firebase storage download token will be generated on the resized image(s) if the original metadata contains a token). Note that you can optionally configure the extension to overwrite the Cache-Control value for the resized image(s).

The extension can publish a resize completion event which you can optionally enable when you install the extension. If you enable events, you can write custom event handlers that respond to these events. You can always enable or disable events later. Events will be emitted via Eventarc.

Detailed configuration information

To configure this extension, you specify a maximum width and a maximum height (in pixels, px). This extension keeps the aspect ratio of uploaded images constant and shrinks the image until the resized image's dimensions are at or under your specified max width and height.

For example, say that you specify a max width of 200px and a max height of 100px. You upload an image that is 480px wide by 640px high, which means a 0.75 aspect ratio. The final resized image will be 75px wide by 100px high to maintain the aspect ratio while also being at or under both of your maximum specified dimensions.

Additional setup

Before installing this extension, make sure that you've set up a Cloud Storage bucket in your Firebase project.

NOTE: As mentioned above, this extension listens for all changes made to the specified Cloud Storage bucket. This may cause unnecessary function calls. It is recommended to create a separate Cloud Storage bucket, especially for images you want to resize, and set up this extension to listen to that bucket.

Multiple instances of this extension

You can install multiple instances of this extension for the same project to configure different resizing options for different paths. However, as mentioned before this extension listens for all changes made to the specified Cloud Storage bucket. That means all instances will be triggered every time a file is uploaded to the bucket. Therefore, it is recommended to use different buckets instead of different paths to prevent unnecessary function calls.

Billing

To install an extension, your project must be on the Blaze (pay as you go) plan

  • You will be charged a small amount (typically around $0.01/month) for the Firebase resources required by this extension (even if it is not used).
  • This extension uses other Firebase and Google Cloud Platform services, which have associated charges if you exceed the service's no-cost tier:
  • Cloud Storage
  • Cloud Functions (Node.js 10+ runtime. See FAQs)
  • If you enable events Eventarc fees apply.

Cara menginstal ekstensi ini

Menggunakan Firebase console

Anda dapat menggunakan Firebase console untuk menginstal dan mengelola ekstensi.

Instal menggunakan konsol

Menggunakan Firebase CLI

Anda juga dapat menggunakan Firebase CLI untuk menginstal dan mengelola ekstensi:

Langkah 1: Jalankan perintah npm berikut untuk menginstal CLI atau mengupdate ke versi CLI terbaru.

npm install -g firebase-tools
Tidak berhasil? Lihat referensi Firebase CLI atau ubah izin npm Anda.

Langkah 2: Siapkan direktori project Firebase baru atau buka direktori yang sudah ada

Langkah 3: Tambahkan ekstensi ini ke manifes ekstensi Anda dengan menjalankan

firebase ext:install firebase/storage-resize-images --local --project=projectId_or_alias

Langkah 4 (Opsional): Uji ekstensi ini secara lokal dengan Firebase Emulator Suite

firebase emulators:start

Langkah 5: Deploy ekstensi dalam manifes ke project Anda

firebase deploy --only extensions --project=projectId_or_alias
Dukungan
Cloud Storage
Penulis
Lisensi
Apache-2.0
Versi
0.1.28