Images
Image Plugin Guide
The Image Plugin in Servoy provides a robust set of tools for working with images, enabling the manipulation, transformation, and retrieval of image data. The primary return type when working with images is the JSImage object, which allows access to various image properties and supports transformations like rotating, flipping, and resizing. These capabilities make the Image Plugin ideal for applications that require image processing, such as profile picture uploads, product image management, or generating visual previews.
Key Use Cases:
Dynamic Image Loading:
Loading Images from Various Sources: This flexibility is particularly useful in applications where images may be stored in different formats or locations, such as on local filesystems or in databases as blobs.
Generating Image Thumbnails for Previews: Load images and resize them to create thumbnails or previews, which can be displayed in forms or galleries without affecting page load times. Thumbnails are often needed for user interfaces displaying multiple images, such as product listings.
Image Transformation:
Editing and Enhancing Images: Transform images by resizing, rotating, or flipping them. This is particularly useful for photo management applications where users might upload images in varying orientations or sizes, and the application needs to standardize them.
Creating Standardized Image Sizes: For websites or applications that require images in specific dimensions (e.g., profile photos, product images), resizing ensures all uploaded images meet dimension requirements.
Image Metadata Extraction:
Accessing Metadata: Extract metadata from supported image formats (currently only JPEG). Metadata, such as EXIF data, can provide useful details like creation date, camera model, and orientation. This is essential for applications in digital asset management, where metadata is used for cataloging and organizing images.
Generating Thumbnails from Metadata: Some images (e.g., JPEGs) contain embedded thumbnails in their metadata. These can be extracted to generate quick previews without the need for resizing, reducing processing overhead.
Saving Image Data:
Storing Transformed Images: After applying transformations, retrieve the binary data of the edited image, which can then be stored in a database or saved to a file. This is especially valuable in scenarios where images are modified frequently or saved as different versions.
Exporting Images: Use binary data to export images to specific locations in the file system or for download by users.
Getting Image Info
Retrieve essential information about an image, such as its width, height, and content type, along with embedded metadata if available (currently supported for JPEG only).
Code Example:
Methods Used:
Transforming an Image
The JSImage object supports various transformations, such as rotating, flipping, and resizing. Each transformation returns a new JSImage instance with the applied change.
Rotate
Rotate the image by a specified degree.
Method Used: rotate(degrees)
Flip
Flip the image vertically (type=0) or horizontally (type=1).
Method Used: flip(type)
Scale
Resize the image to a specific width and height.
Method Used: resize(width, height)
Writing Image Data
Once an image is transformed, you can save it by retrieving the image data in byte array format. This data can then be stored in the database or saved to a file.
Code Example:
Method Used: getData()
Last updated