🧩 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:
- 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.
- Set Quality: You specify a quality value between 0 and 100 to control the trade-off between file size and image clarity.
- 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.
- 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
- 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!
Specifications
Package: com.bosonshiggs.imagecompressor
AIX File: com.bosonshiggs.imagecompressor.aix (27.9 KB) (GitHub)
Size: 27,86 KB
Version: 1.0
Minimum API Level: 7
Updated On: 2025-06-21T03:00:00Z
Built & documented using: FAST v3.7.1
Events:
ImageCompressor has total 3 events.
1. ImageSelected
Triggered when an image is selected.
Parameter | Type |
---|---|
imagePath | text |
2. ImageSaved
Triggered when an image is saved.
Parameter | Type |
---|---|
id | number |
filePath | text |
3. ErrorOccurred
Triggered when an error occurs during image compression.
Parameter | Type |
---|---|
errorMessage | text |
Methods:
ImageCompressor has total 2 methods.
1. PathFromUri
Converts a content URI to a file system path.
- 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
- Input type:
boolean