Source for file Imlib.php
Documentation is available at Imlib.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Jason Rust <jrust@rustyparts.com> |
// +----------------------------------------------------------------------+
// $Id: Imlib.php 258825 2008-04-30 23:00:13Z cweiske $
require_once 'Image/Transform.php';
// $img = new Image_Transform::factory('Imlib');
// $img->load('test.png');
// $img->addText(array('text'=>"Rotation $angle",'x'=>0,'y'=>100,'font'=>'arial.ttf','color'=>'#ffffff'));
// {{{ class Image_Transform_Driver_Imlib
* Performs image manipulation with the imlib library.
* @see http://mmcc.cx/php_imlib/index.php
* @author Jason Rust <jrust@rustyparts.com>
* @package Image_Transform
* Holds the image file for manipulation
* Holds the original image file
* @return mixed true or or a PEAR error object on error
if (!PEAR ::loadExtension ('imlib')) {
'Couldn\'t find the imlib extension.',
* @return mixed TRUE or a PEAR error object on error
if (PEAR ::isError ($result)) {
* Adds text to the image. Note that the angle should be one of the following
* constants: IMLIB_TEXT_TO_RIGHT, IMLIB_TEXT_TO_LEFT, IMLIB_TEXT_TO_DOWN,
* IMLIB_TEXT_TO_UP, IMLIB_TEXT_TO_ANGLE
* @param array options Array contains options
* 'text' The string to draw
* 'x' Horizontal position
* 'size' Size of the fonts in pixel
* 'angle' A imlib direction constant
* @return TRUE or PEAR Error object on error
'text' => 'This is Text',
'color' => array (255 ,0 ,0 ),
'angle' => IMLIB_TEXT_TO_RIGHT ,
include_once 'Image/Transform/Driver/ColorsDefs.php';
$color = isset ($colornames[$color]) ? $colornames[$color] : false;
$fontResource = imlib_load_font ($font . '/' . $size);
imlib_text_draw ($this->imageHandle, $fontResource, $x, $y, $text, $angle, $color[0 ], $color[1 ], $color[2 ], 255 );
* Rotate image by the given angle
* @param int $angle Rotation angle
* @return TRUE or PEAR Error object on error
// when rotating it creates a bigger picture than before so that it can rotate at any angle
// so for right angles we crop it back to the original size
if (abs($angle) == 90 || $angle == 270 ) {
$y_pos = ($new_x - $this->img_x) / 2;
$x_pos = ($new_y - $this->img_y) / 2;
$x_pos = ($new_x - $this->img_x) / 2;
$y_pos = ($new_y - $this->img_y) / 2;
* Crops the current image to a specified height and width
* @param int $in_cropWidth The width of the new image
* @param int $in_cropHeight The height of the new image
* @param int $in_cropX The X coordinate on the image to start the crop
* @param int $in_cropY The Y coordinate on the image to start the crop
* @return TRUE or PEAR Error object on error
function crop($in_cropWidth, $in_cropHeight, $in_cropX, $in_cropY)
if (!$this->_intersects ($in_cropWidth, $in_cropHeight, $in_cropX, $in_cropY)) {
$this->imageHandle = imlib_create_cropped_image ($this->imageHandle, $in_cropX, $in_cropY, $in_cropWidth, $in_cropHeight);
$this->img_x = $in_cropWidth;
$this->img_y = $in_cropHeight;
* Save the image file. Determines what type of image to save based on extension.
* @param $filename string the name of the file to write to
* @param $type string (optional) define the output format, default
* is the current used format
* @param $quality int (optional) output DPI, default is 75
* @return TRUE on success or PEAR Error object on error
function save($filename, $type = '', $quality = 75 )
return PEAR ::raiseError ('Invalid image', true );
$type = ($type == '') ? $this->type : $type;
$return = imlib_save_image ($this->imageHandle, $filename, $err, $quality);
return PEAR ::raiseError ('Couldn\'t save image. Reason: ' . $err, true );
* Display image without saving and lose changes
* This method adds the Content-type HTTP header
* @param string $type (optional) (JPG,PNG...);
* @param int $quality (optional) 75
* @return TRUE on success or PEAR Error object on error
function display($type = '', $quality = null )
return PEAR ::raiseError ('Invalid image', true );
$type = ($type == '') ? $this->type : $type;
$return = imlib_dump_image ($this->imageHandle, $err, $quality);
return PEAR ::raiseError ('Couldn\'t output image. Reason: ' . $err, true );
* @param int $new_x New width
* @param int $new_y New height
* @param mixed $options Optional parameters
* @return TRUE on success or PEAR Error object on error
function _resize($new_x, $new_y, $options = null )
return PEAR ::raiseError ('You have already resized the image without saving it. Your previous resizing will be overwritten', null , PEAR_ERROR_TRIGGER , E_USER_NOTICE );
// {{{ _get_image_details()
* @return TRUE on success or PEAR Error object on error
* @return TRUE on success, PEAR Error object on error
* @return TRUE on success, PEAR Error object on error
Documentation generated on Mon, 11 Mar 2019 15:48:00 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|