[F/OS] Extension to compress images from 0% to 100% quality

🧩 ImageCompressor

An extension for MIT App Inventor 2.
An extension for compressing images to JPEG, PNG, or WebP.

Summary

The ImageCompressor extension makes it easy to reduce (compress) image file sizes directly within your App Inventor app. It’s designed for anyone who needs to shrink photos before saving them to a device or uploading them online, saving storage space and speeding up transfers.

How it works in practice:

  1. Select Image: The user picks a photo from their device, and the extension notifies your app via the ImageSelected event when the image is ready for processing.
  2. Set Quality: You specify a quality value between 0 and 100 to control the trade-off between file size and image clarity.
  3. Save Compressed File: The extension creates a new compressed copy in a folder named “CompressedImages”, automatically adding numbers to the file name if a file with the same base name already exists.
  4. Return Events: App Inventor blocks automatically respond to three events:
    • ImageSelected — image has been chosen
    • ImageSaved — compression finished and saved; returns the file path and ID
    • ErrorOccurred — something went wrong; returns an error message
  5. Optional Logging: Enable LogEnabled(true) to see debug messages in Logcat.

Advantages for non-experts:

  • No complex code required: Just use blocks to call extension functions.
  • Space savings: Compressed images take up less memory and load faster.
  • Supports common formats: JPEG, PNG, and WebP.
  • Runs in background: Compression happens off the main thread, so your app stays responsive.

Example block usage:

// Call CompressImage
ImageCompressor1.CompressImage(
    pathToImage,
    "myCompressedPhoto",
    80,
    1
)

Then handle these events:

// When compression finishes
when ImageCompressor1.ImageSaved(id, savedPath) do
    NotifyUser("Saved to: " + savedPath)
end

// If an error occurs
when ImageCompressor1.ErrorOccurred(errorMsg) do
    NotifyUser("Error: " + errorMsg)
end

With ImageCompressor, even App Inventor beginners can optimize images quickly and efficiently without worrying about complex code!

:memo: Specifications


:package: Package: com.bosonshiggs.imagecompressor
:file_folder: AIX File: com.bosonshiggs.imagecompressor.aix (27.9 KB) (GitHub)
:floppy_disk: Size: 27,86 KB
:gear: Version: 1.0
:mobile_phone: Minimum API Level: 7
:date: Updated On: 2025-06-21T03:00:00Z
:laptop: Built & documented using: FAST v3.7.1

Events:

ImageCompressor has total 3 events.

1. ImageSelected

Triggered when an image is selected.
ImageSelected_Event

Parameter Type
imagePath text

2. ImageSaved

Triggered when an image is saved.
ImageSaved_Event

Parameter Type
id number
filePath text

3. ErrorOccurred

Triggered when an error occurs during image compression.
ErrorOccurred_Event

Parameter Type
errorMessage text

Methods:

ImageCompressor has total 2 methods.

1. PathFromUri

Converts a content URI to a file system path.
PathFromUri_Get_Method

  • Return type: text
Parameter Type
stringUri text

2. CompressImage

Compresses the image at the given path to the specified format and quality.

Parameter Type
imagePath text (asset blocks)
imageName text
quality number
id number

Setter:

ImageCompressor has total 1 setter property.

1. LogEnabled

Enable or disable logging to Logcat
LogEnabled_Set_Property

  • Input type: boolean

All blocks

8 Likes

Very good extension

@Passos_0213 :people_hugging:

4 Likes

Works on Android 13+?

1 Like

Now the extension is free and open source (F/OS)

2 Likes