Features

Asido offers some of the most basic and most frequently used image transformation features. Here’s a bit more detailed overview of Asido features, with comments, examples, etc. The features are arranged more or less from the most often used ones and popular (like watermark, resize and convert) down to the ones that least used (like rotate, flip, crop, grayscale, etc).

Watermark

Watermarking is a very common operation required by a variety of web projects. Here’s an example how Asido does it:

save(ASIDO_OVERWRITE_ENABLED);
?>

As for all Asido operations you have to first create an Asido_Image object and then manipulate it. The watermark  image itself must from one of the supported by the currently loaded driver file formats. The position of the watermark (gravity) can be set by using one of the ten available constants: ASIDO_WATERMARK_TOP_LEFT, ASIDO_WATERMARK_TOP_CENTER, ASIDO_WATERMARK_TOP_RIGHT, ASIDO_WATERMARK_MIDDLE_LEFT, ASIDO_WATERMARK_MIDDLE_CENTER, ASIDO_WATERMARK_MIDDLE_RIGHT, ASIDO_WATERMARK_BOTTOM_LEFT, ASIDO_WATERMARK_BOTTOM_CENTER, ASIDO_WATERMARK_BOTTOM_RIGHT and ASIDO_WATERMARK_TILE. The last one, ASIDO_WATERMARK_TILE, is used to perform a tile watermark on the image. If the position(gravity) is omitted as argument, the default gravity is ASIDO_WATERMARK_BOTTOM_RIGHT. All the non-tile positions have aliases for those of you who prefer to use the North, East, South and West directions: ASIDO_WATERMARK_NORTH_WEST, ASIDO_WATERMARK_NORTH, ASIDO_WATERMARK_NORTH_EAST, ASIDO_WATERMARK_WEST, ASIDO_WATERMARK_CENTER, ASIDO_WATERMARK_MIDDLE (same as ASIDO_WATERMARK_CENTER), ASIDO_WATERMARK_EAST, ASIDO_WATERMARK_SOUTH_WEST, ASIDO_WATERMARK_SOUTH, ASIDO_WATERMARK_SOUTH_EAST.


There are situations in which it turns out that the watermark image is considerable larger compared to the image that is going to be watermarked. In these scenarios  Asido applies watermark scaling. This means that the watermark is resized so it dimensions become some portion of the image that is going to be watermarked. This feature can be turned on and off by using the ASIDO_WATERMARK_SCALABLE_ENABLED and ASIDO_WATERMARK_SCALABLE_DISABLED constants. By default, the featured is enabled, and the scaling factor is taken from the ASIDO_WATERMARK_SCALABLE_FACTOR constant. If you want you can re-define this constant, or just provide a decimal value (0 < scaling_factor < 1) instead. By default, the scaling factor is 0.25 (1/4).

/**
* Put the watermark with the scaling feature enabled
*/
Asido::watermark($i1, 'watermark_03.png', ASIDO_WATERMARK_BOTTOM_RIGHT, ASIDO_WATERMARK_SCALABLE_ENABLED);
 
/**
* Put the watermark with the scaling feature disabled
*/
Asido::watermark($i1, 'watermark_03.png', ASIDO_WATERMARK_CENTER, ASIDO_WATERMARK_SCALABLE_DISABLED);
/**
* Put the watermark with the scaling factor 0.66
*/
Asido::watermark($i2, 'watermark_04.png', ASIDO_WATERMARK_TOP_LEFT, ASIDO_WATERMARK_SCALABLE_ENABLED, 0.66);
 
/**
* Put the watermark with the scaling factor 0.75
*/
Asido::watermark($i2, 'watermark_04.png', ASIDO_WATERMARK_BOTTOM_RIGHT, ASIDO_WATERMARK_SCALABLE_ENABLED, 0.75);

Resize

Asido offers various resizing features. First, let’s go over the proportional resize. If all argumens except $width and $height are omitted, Asido will perform a propprtional resize, which will try to fit the image inside the provided "resize frame" (by the $width and $height arguments) while keeping its proportions. As for all Asido operations you have to first create an Asido_Image object and then manipulate it.

save(ASIDO_OVERWRITE_ENABLED);
?>

However, you can resize by only one of the dimensions: either width or height. This will result in a proportional resize, where the "other" dimension is resized proportionaly in order to keep the image proportions.

/**
* Resize the image proportionally only by setting only the height, and the width will be corrected accordingly
*/
Asido::resize($i1, 0, 400);
/**
* Resize the image proportionally only by setting only the width, and the height will be corrected accordingly
*/
Asido::resize($i1, 400, 0);
 Source Image (640x480)

 Result w/ resizing by width only (400x300)

 Result w/ resizing by height only (533x400)

The last argument for the resize operation is the type or the mode of the resizing operations. The default value is ASIDO_RESIZE_PROPORTIONAL, which means that a proportional resize is going to be performed. The other two are ASIDO_RESIZE_STRETCH and ASIDO_RESIZE_FIT – those will be covered below in the sections about the Stretch and Fit features.


Width

This is an easy way to do a proportional resize only by the width dimension.

/**
* Resize the image proportionally only by setting only the width, and the height will be corrected accordingly
*/
Asido::width($i1, 600);
 Source Image (640x480)

 Result w/ resizing only by one dimension [width] (600x450)

Height

This is an easy way to do a proportional resize only by the height dimension.

/**
* Resize the image proportionally only by setting only the height, and the width will be corrected accordingly
*/
Asido::height($i1, 400);
 Source Image (640x480)

 Result w/ resizing only by one dimension [height] (533x400)

Stretch

This feature performs a disproportional resize, or stretch: the image will be stretched to fit perfectly inside the "resize frame" (provided by the $width and $height arguments). In general this feature is not going to be used very often, but it is good to have it inside our arsenal just in case a situation requiring such feature emerges.

/**
* Resize the image by stretching it and using default resizing method
*/
Asido::resize($i1, 500, 500, ASIDO_RESIZE_STRETCH);
/**
* Resize the image by stretching it and using `alias` method
*/
Asido::stretch($i1, 500, 500);
 Source Image (640x480)

 Result w/ stretch resizing (500x500)

Fit

This type of resize is a proportional resize, but its behaviour is affected by the size(dimensions) of the image. If the image is smaller then the "resize frame" (provided by the $width and $height arguments), it will NOT be resized: it will resize only if any of its dimensions are bigger than those of the "resize frame". This feature is very handy – it will save you the pixelation effect if you are trying to resize smaller images to fit into larger "frames".

/**
* Resize the image by fitting it inside the 800x800 frame: in
* fact it will not be resized because it is smaller (640x480)
*/
Asido::Fit($i1, 800, 800);
/**
* Resize the image by fitting it inside the 400x400 frame: the image
* will do be resized by making it fit inside the 400x400 "mold"
*/
Asido::Fit($i2, 400, 400);
 Source Image (640x480)

 Result w/ fit 800x800 resizing (the same as original)

 Result w/ fit 400x400 resizing (indeed resized to 400x300)

Frame

This is another handy resize feature. It is a kind of compromise between the stretch resize and the proportional resize. This  feature will resize the image proportionally using the Fit feature (not the regular proportional resize) and will place it in the center of a canvas, which has  $width and $height as its dimensions, and $color as its background. This is very usefull, because it offers the ablity to fit virtually any image inside any resize frame – and the proportions will not matter: you can fit a landcape inside a square, or a square inside a portrait, etc. The $color argument is used in the same manner as it is used when rotating by custsom angles – to fill the left blank areas.

/**
* Resize the image by putting it inside a square frame (300x300) with `rgb(177,77,37)` as background.
*/
Asido::Frame($i1, 300, 300, Asido::Color(39, 107, 20));
 Source Image (640x480)

 Result w/ frame resizing

Convert

This feature is used to transform an image file from one to another file format. Different drivers support different set of file formats, but all of them support the most common "web" formats: JPEG, PNG and GIF. As for all Asido operations you have to first create an Asido_Image object and then manipulate it. In order to change the image file type, you need to specify a new mime-type for that image. There are three predefined constants for all the "web" formats: ASIDO_MIME_JPEG, ASIDO_MIME_GIF and ASIDO_MIME_PNG

save(ASIDO_OVERWRITE_ENABLED);
?>

Rotate

While watermarking, resizing and converting are the most popular image transformation tasks, the ones from this list starting this one – rotating – are more "exotic" and not that oftenly used. The rotating as its name suggests is used to rotate an image. As for all Asido operations you have to first create an Asido_Image object and then manipulate it. The most common scenarios are to rotate images by 90o, 180o or 270o.

/**
* Rotates the image by 90, 180 and 270 degrees
*/
Asido::Rotate($i1, 90);
Asido::Rotate($i1, 180);
Asido::Rotate($i1, 270);

Asido also supports rotation by any custom angle. For all those "custom" rorations there are blank areas enclosed by the rotated sides of the image and the rectangular sides of the resulting image. For "those blank areas" the rotate feature uses a color provided as additional argument, which is applied to the blank areas. If this argument is omittted, then white color will be used

/**
* Rotates the image by 30 degrees, filling the blank areas left by the rotate with a nice green color
*/
Asido::Rotate($i1, 30, Asido::Color(39, 107, 20));
 Source Image

 Result w/ 30 degrees rotation

Flip

Flip stands for creating a vertical mirror of an image. As for all Asido operations you have to first create an Asido_Image object and then manipulate it.

/**
* Flip it 😉
*/
Asido::Flip($i1);
 Source Image

 Result w/ flipping the image

Flop

Flops stands for creating a horizontal mirror of an image. As for all Asido operations you have to first create an Asido_Image object and then manipulate it.

/**
* Flop it 😉
*/
Asido::Flop($i1);
 Source Image

 Result w/ flopping the image

Crop

Crop is not a very commonly used feature, but it best to have it available and not use it, instead of to need ti and to not have it implemented… right ? As for all Asido operations you have to first create an Asido_Image object and then manipulate it. In order to crop the image you need to specify the upper left corner of the "crop frame" with the $x and $y arguments, aswell as the $width and the $height of the "crop frame":

/**
* Crop a portion of the image from the upper left corner
*/
Asido::Crop($i1, 0, 0, 300, 300);
 Source Image

 Result w/ cropping

Copy

This is not so much of a common image transformation task, but in certain situations it is indeed useful – like using  Asido to create a very basic CAPTCHA image. As for all Asido operations you have to first create an Asido_Image object and then manipulate it. The image that you are copying must be one of the supported (by currently active driver) image file formats.

/**
* Copy the image with over the resulting image
*/
Asido::copy($i1, 'copy_01.png', 15, 15);
/** * Copy an image using negative coordinates */ Asido::copy($i1, 'copy_02.jpg', -35, -35);

If the image has alpha transaprency, it is kept during the copy operation. Under the hood, this very same functionality is utilized in the watermark feature, so keeping the "alpha" is very important.

Grayscale

Making an image grayscale is not of a common image transformation task, but it is a good asset in the set of features Asido offers.

/**
* Do the grayscale baby 😉
*/
Asido::GreyScale($i1);
 Source Image

 Result w/ greyscaling applied

Powered by WordPress
Asido: PHP Image Processing Solution