Image Resize

Built-In function to resize image.

CodeMash includes a built-in function for image resizing and optimization that can be easily integrated into your project with just a few clicks. This function is handy for optimizing pictures uploaded to your app or website by users, as it allows you to resize and optimize large images to reduce their file size and improve performance.

Enable the Image Resize function

  1. Go to the Code module within the CodeMash dashboard.

  2. From the functions menu, click on the "Add New" button.

  3. Click on the "Resize Image" function to add it to your project.

  4. Once the function has been added, you can access it from the functions menu and configure it according to your needs. You can specify the desired resize and optimization settings, such as the target image size, directory where to store, and prefix.

  5. You can use the function from either the API or from database triggers. This means that you can call the function from your app or website or have it automatically execute when certain events occur in your database. This can help automate image processing tasks or integrate with other systems.

The Image Resize function is deployed to the cloud. This means that it runs on demand and is only charged for the execution time and resources used. This can be more cost-effective and scalable than running a traditional server-based solution.

The function includes all necessary libraries and configurations for image resizing and optimization. This makes it easy to use, as you don't have to worry about setting up and maintaining the necessary infrastructure.

The default parameters of this JSON object are as follows:

  • "resizes": This is an array of objects, each representing a resize operation performed on the image.

  • "size": This is a string that specifies the target size of the resized image. The size can be specified in pixels (e.g., "300x300") or as a percentage of the original image size (e.g., "10%").

  • "directory": This is a string that specifies the directory where the resized image will be stored.

  • "prefix": This is a string that will be added as a prefix to the file name of the resized image.

  • "suffix": This is a string that will be added as a suffix to the file name of the resized image.

In the example JSON object, there are two resize operations defined. The first operation will resize the image to a size of 300x300 pixels and store the resized image in the "./thumbnails" directory, with the prefix "resized-" and the suffix "_medium" added to the file name. The second operation will resize the image to 10% of its original size and store the resized image in the same "./thumbnails" directory, with the same prefix "resized-" and the suffix "_small" added to the file name.

N.B. The CodeMash built-in function for image resizing and optimization does not include image rescale. It only performs image resizing and optimization. To perform an image rescale, you will need to use a different method.

Image resize refers to changing the dimensions of an image, typically by specifying a new width and height in pixels. This can be useful if you want to make an image smaller or larger without distorting its aspect ratio (the ratio of its width to its height).

Image optimization refers to reducing the file size of an image without sacrificing quality. This can be useful if you want to speed up the loading time of your website or reduce bandwidth usage. Various techniques for optimizing images include compressing them, removing unnecessary metadata, and using appropriate image formats.

Last updated