PHP Classes
elePHPant
Icontem

GImage PHP Canvas to Image: Create and compose canvas images from other images

Recommend this page to a friend!
  Info   View files Example   View files View files (18)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2016-08-08 (20 days ago) RSS 2.0 feedStarStarStarStar 64%Total: 452 This week: 1All time: 5,830 This week: 961Up
Version License PHP version Categories
canvas-image 1.5.4MIT/X Consortium ...5.3PHP 5, Graphics
Description Author

This package can create and compose canvas images from other images.

It provides classes for creating image objects defined by colored rectanges, images from files and text.

An additional canvas class can compose complex images using images defined by the other classes easier.

The composed images may be saved to files in the PNG and JPEG formats or displayed as the current script output.

Picture of Jose Luis Quintana
  Performance   Level  
Name: Jose Luis Quintana <contact>
Classes: 1 package by
Country: Peru Peru
Age: ???
All time rank: 31839 in Peru Peru
Week rank: 812 Up3 in Peru Peru Up

Details

GImage

Build Status Latest Stable Version Latest Unstable Version Total Downloads License

> A simple PHP library for easy image handling.

GImage is a simple extended library based on PHP Image Processing and GD for easy image handling. With GImage you can read, create, crop, resize, rotate, embed text, merge and save your JPG or PNG images easy. GImage require PHP 5.3 or higher and GD Extension.

A simple presentation card with GImage

View sample code

Install

$ composer require joseluisq/gimage

Usage

Basic

Working with external JPG image and output on browser as PNG format.

<?php
require 'src/gutils.php';
require 'src/gimage.php';

// Loading an image (200x200) from an URL (or local path)
$avatar = new GImage();
$avatar->load('http://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50?s=200.jpg');
// Scaling to 50% (100x100)
$avatar->scale(50);
// Changing to PNG format
$avatar->toPNG();
// Preserving the image before saving or outputting
$avatar->preserve();
// Saving to local path
$avatar->save('my-avatar.png');
// Preparing for destroy the resource after outputting
$avatar->preserve(false);
// Outputting on the browser and destroy the resource.
$avatar->output();

Using GFigure

Creating a simple green rectangle.

<?php
require 'src/gutils.php';
require 'src/gfigure.php';
require 'src/gimage.php';

// Setting rectangle sizes
$rectangle = new GFigure(500, 300);
// Setting a green background color
$rectangle->setBackgroundColor(170, 188, 147);
// Creating the figure
$rectangle->create();
// Outputting JPG image (by default) on the browser.
$rectangle->output();

Creating a simple presentation card

Creating a simple presentation card with GImage, GCanvas, GFigure and GText.

<?php
require 'src/gutils.php';
require 'src/gimage.php';
require 'src/gfigure.php';
require 'src/gtext.php';
require 'src/gcanvas.php';

$avatar_image = new GImage();
$avatar_image->load('http://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50?s=100.jpg');
$avatar_image->setTop(60);
$avatar_image->setLeft(70);

$about_text = new GText("MY AWESOME PRESENTATION CARD GENERATED WITH GIMAGE");
$about_text->setSize(16);
$about_text->setWidth(300);
$about_text->setLeft(210);
$about_text->setTop(75);
$about_text->setColor(204, 164, 116);
$about_text->setFontface('fonts/Lato-Light.ttf');

$twitter_text = new GText('@username');
$twitter_text->setSize(11);
$twitter_text->setWidth(70);
$twitter_text->setLeft(450);
$twitter_text->setTop(210);
$twitter_text->setColor(130, 127, 125);
$twitter_text->setFontface('fonts/Lato-Regular.ttf');

$canvas_figure = new GFigure(550, 250);
$canvas_figure->setBackgroundColor(47, 42, 39);
$canvas_figure->create();

$avatar_box = new GFigure($avatar_image->getWidth() + 16, $avatar_image->getHeight() + 17);
$avatar_box->setBackgroundColor(63, 56, 52);
$avatar_box->setLeft($avatar_image->getLeft() - 7);
$avatar_box->setTop($avatar_image->getTop() - 8);
$avatar_box->create();

$avatar_box2 = new GFigure($avatar_image->getWidth() + 3, $avatar_image->getHeight() + 19);
$avatar_box2->setBackgroundColor(79, 72, 67);
$avatar_box2->setLeft($avatar_image->getLeft() + 7);
$avatar_box2->setTop($avatar_image->getTop() - 9);
$avatar_box2->create();

$avatar_box3 = new GFigure(120, 240);
$avatar_box3->setBackgroundColor(63, 56, 52);
$avatar_box3->create();

$line_vertical = new GFigure(600, 10);
$line_vertical->setBackgroundColor(119, 99, 77);
$line_vertical->setTop(240);
$line_vertical->create();

$line_horizontal = new GFigure(1, 240);
$line_horizontal->setBackgroundColor(79, 72, 67);
$line_horizontal->setLeft(120);
$line_horizontal->create();

$canvas = new GCanvas();
$canvas->from($canvas_figure);
$canvas->append(array(
  $line_horizontal,
  $avatar_box2,
  $avatar_box3,
  $avatar_box,
  $avatar_image,
  $about_text,
  $twitter_text,
  $line_vertical
));
$canvas->toPNG();
$canvas->draw();
$canvas->save('card.png');

Contribution

If you would like to contribute pull requests and issues will be welcome! Feature requests are welcome. Please before sending some feature requests make sure provide as much detail and context as possible.

Documentation

Read API Documentation

License

MIT license

© 2016 Josť Luis Quintana

  Files folder image Files  
File Role Description
Files folder imageexamples (5 files)
Files folder imagesrc (1 file, 1 directory)
Files folder imagetest (2 files, 1 directory)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file license.md Data Auxiliary data
Accessible without login Plain text file readme.md Data Auxiliary data

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file card.php Example Example script
  Accessible without login Plain text file crop.php Example Example script
  Accessible without login Plain text file rotate.php Example Example script
  Accessible without login Plain text file text.php Example Example script
  Accessible without login Plain text file _config.php Aux. Auxiliary script

  Files folder image Files  /  src  
File Role Description
Files folder imagegimage (5 files)
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script

  Files folder image Files  /  src  /  gimage  
File Role Description
  Plain text file gcanvas.php Class Class source
  Plain text file gfigure.php Class Class source
  Plain text file gimage.php Class Class source
  Plain text file gtext.php Class Class source
  Plain text file gutils.php Class Class source

  Files folder image Files  /  test  
File Role Description
Files folder imagespec (1 file)
  Accessible without login Plain text file config.xml Data Auxiliary data
  Accessible without login Plain text file phpunit Data Auxiliary data

  Files folder image Files  /  test  /  spec  
File Role Description
  Plain text file GImageTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:452
This week:1
All time:5,830
This week:961Up
User Ratings User Comments (1)
 All time
Utility:91%StarStarStarStarStar
Consistency:91%StarStarStarStarStar
Documentation:-
Examples:100%StarStarStarStarStarStar
Tests:-
Videos:-
Overall:64%StarStarStarStar
Rank:658
 
It is a nice Widget
2 years ago (Thomas Stoffregen)
80%StarStarStarStarStar