PHP Classes
elePHPant
Icontem

File: docs/examples/resizing.md

Recommend this page to a friend!
  Classes of Jose Luis Quintana  >  GImage  >  docs/examples/resizing.md  >  Download  
File: docs/examples/resizing.md
Role: Example script
Content type: text/markdown
Description: Example script
Class: GImage
Create graphic images with a fluent interface
Author: By
Last change:
Date: 8 months ago
Size: 1,121 bytes
 

Contents

Class file image Download

Resizing

Width resizing

Resizing an image proportionally basing 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 basing 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 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');