PHP Classes

File: examples/resource.php

Recommend this page to a friend!
  Classes of Jose Luis Quintana   GImage PHP Canvas to Image   examples/resource.php   Download  
File: examples/resource.php
Role: Example script
Content type: text/plain
Description: Example script
Class: GImage PHP Canvas to Image
Create and compose canvas images from other images
Author: By
Last change: docs: improve example pages and code files
refactor: minor project docs updates
feat: load an image from a resource or `\GdImage`
Date: 8 months ago
Size: 989 bytes


Class file image Download
 * This file is part of GImage.
 * (c) Jose Quintana <>
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.

 * Rendering an image from a `resource` or `GdImage`.
 * @author Jose Quintana <>

namespace GImage\Examples;


__DIR__ . '/_config.php';
__DIR__ . '/../tests/bootstrap.php';

// Create a 240x100 image
$width = 240;
$height = 100;
$rectangle = imagecreatetruecolor($width, $height);
$green = imagecolorallocate($rectangle, 0, 255, 0);
imagefilledrectangle($rectangle, 0, 0, $width, $height, $green);

// Load and process the rectangle image resource
$img = new Image();
// we need to indicate GImage about the image type in this case
// scale to 50%
// let's change again the image type just for fun