PHP Classes

File: examples/resource.php

Recommend this page to a friend!
  Classes of Jose Luis Quintana   GImage   examples/resource.php   Download  
File: examples/resource.php
Role: Example script
Content type: text/plain
Description: Example script
Class: GImage
Create graphic images with a fluent interface
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: 1 year ago
Size: 989 bytes
 

Contents

Class file image Download
<?php
/*
 * This file is part of GImage.
 *
 * (c) Jose Quintana <https://joseluisq.net>
 *
 * 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 <https://joseluisq.net>
 */

namespace GImage\Examples;

use
GImage\Image;

require
__DIR__ . '/_config.php';
require
__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();
$img
   
->load($rectangle)
   
// we need to indicate GImage about the image type in this case
   
->toPNG()
   
// scale to 50%
   
->scale(0.5)
   
// let's change again the image type just for fun
   
->toJPG()
    ->
save('rectangle.jpg');