Resizing and cropping images
Some short examples in resizing and cropping topics.
Examples
- resizing the width to 150 px, maintaining the aspect ratio:
w:150
width:150
use shardimage\shardimagephp\factories\Transformation;
$transformations = (new Transformation())->width(150);
- resizing the height to 50 px, maintaining the aspect ratio:
h:50
height:50
use shardimage\shardimagephp\factories\Transformation;
$transformations = (new Transformation())->height(50);
- 300x80 px cropping the image still maintaining the aspect ratio:
w:300_h:80
use shardimage\shardimagephp\factories\Transformation;
$transformations = (new Transformation())->width(300)->height(80);
- highlighting 300x80 px strip from the image:
- resizing width of the original image to 300px
w:300
- adding slightly blur effect
e:blur:250
(w:300_e:blur:250
) - add lighten effect to the image (white background + opacity)
w:300_e:blur:250_e:o:30
- adding the original picture as a layer to a new transformation group
w:300_h:80_l:lo:steve
- resizing width of the original image to 300px
w:300_e:blur:250_e:o:30/w:300_h:80_l:lo:steve
use shardimage\shardimagephp\factories\Transformation;
$transformations = (new Transformation())->width(300)->blur(250)->opacity(30)->group()->width(300)->height(80)->overlay('steve');
- 100x100px resizing without maintaining aspect ratio:
w:100_h:100_c:scale
use shardimage\shardimagephp\factories\Transformation;
$transformations = (new Transformation())->width(100)->height(100)->scale();
- 200x200px image with focusing on face round the corners
- focusing on face
g:face
- resizing to 200x200px
wh:200
(g:face/wh:200
) - rounding the corners with max radius
ro:max
(g:face/wh:200_ro:max
)
- focusing on face
g:face/wh:200_ro:max
use shardimage\shardimagephp\factories\Transformation;
$transformations = (new Transformation())->gFace()->group()->size(200)->roundMax();
Resizing the image width to 200px, without cropping and filling to 200x200px:
- resizing to 200px
w:200
- new group
/
(w:200/
) - resizing to 200x200px
wh:200
(w:200/wh:200
) - cropping with padding mode
c:pad
(w:200/wh:200_c:pad
) - addig green background to the new image area
bg:green
(w:200/wh:200_c:pad_bg:green
)
- resizing to 200px
w:200/wh:200_c:pad_bg:green
use shardimage\shardimagephp\factories\Transformation;
$transformations = (new Transformation())->width(200)->group()->size(200)->pad()->background('green');