PHP Classes

File: docs/content/examples/resizing.md

Recommend this page to a friend!
  Classes of Jose Luis Quintana   GImage PHP Canvas to Image   docs/content/examples/resizing.md   Download  
File: docs/content/examples/resizing.md
Role: Example script
Content type: text/markdown
Description: Example script
Class: GImage PHP Canvas to Image
Create and compose canvas images from other images
Author: By
Last change:
Date: 1 year ago
Size: 1,122 bytes
 

Contents

Class file image Download

Resizing

Width resizing

Resizing an image proportionally based on the width (height is calculated).

<?php

use GImage\Image;

$image = new Image();
$image
    ->load('https://i.imgur.com/G5MR088.png')
    // Resize from width
    ->resizeToWidth(200)
    // Save on local
    ->save('resize_width_image.png');

Height resizing

Resizing an image proportionally based on the height (width is calculated).

<?php

use GImage\Image;

$image = new Image();
$image
    ->load('https://i.imgur.com/G5MR088.png')
    // Resize from height
    ->resizeToHeight(80)
    // Save on local
    ->save('resize_height_image.png');

!!! tip "Tip"

Use `getPropWidth(height)` and `getPropHeight(width)` to get the proportional `width` or `height` values only.

Scale

The following example scales a PNG image to 120%.

!!! tip "Tip"

The `scale(val)` function value should be between 0 and 1

<?php

use GImage\Image;

$image = new Image();
$image
    ->load('https://i.imgur.com/G5MR088.png')
    // Scale 120%
    ->scale(1.2)
    // Save on local
    ->save('rotate_image.png');