PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Roman Krivosheev   Simple thumbnail   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example
Class: Simple thumbnail
Create thumbnails by cropping or resizing an image
Author: By
Last change: Add croping method and transparent png scale
Date: 12 years ago
Size: 3,119 bytes
 

Contents

Class file image Download
<?php
/**
 * Project: Thumbnail simple resize: lite resize and crop image
 * File: example.php
 *
 * @copyright 2012 Roman Krivosheev, Personal.
 * @author Roman Krivosheev <web.volga@gmail.com>
 * @author Roman Krivosheev (icq: 446666000)
 *
 * include 'includes/Thumbnail.php';
 * $filename = '0001.jpg';
 * $options = array(
 * 'type' => IMAGETYPE_JPEG,
 * 'width' => 150,
 * 'height' => 150,
 * 'method' => THUMBNAIL_METHOD_SCALE_MAX,
 * 'coord_x1' => 0,
 * 'coord_y1' => 0,
 * 'coord_x2' => 0,
 * 'coord_y2' => 0,
 * 'percent' => 0,
 * 'halign' => THUMBNAIL_ALIGN_CENTER,
 * 'valign' => THUMBNAIL_ALIGN_CENTER,
 * 'corner' => 0,
 * 'corcolor' => 'FFFFFF',
 * 'cortransparent' => 0,
 * 'mark' => 0,
 * );
 * Thumbnail::output($filename, 'data.jpg', $options);
 **/
include 'includes/Thumbnail.php';

$thumbnail = dirname(__FILE__).'/img.png';
$filename = dirname(__FILE__).'/original.jpg';
$dir_save = dirname(__FILE__).'/thumbnail/';

/** SCALE MIN IMAGE **/
$options_1 = array(
   
'type' => IMAGETYPE_JPEG,
   
'width' => 150,
   
'height' => 150,
   
'method' => THUMBNAIL_METHOD_SCALE_MIN
);
Thumbnail::output($filename, $dir_save.'image-method-scale-min.jpg', $options_1);

/** SCALE MAX IMAGE **/
$options_2 = array(
   
'type' => IMAGETYPE_JPEG,
   
'width' => 150,
   
'height' => 150,
   
'method' => THUMBNAIL_METHOD_SCALE_MAX
);
Thumbnail::output($filename, $dir_save.'image-method-scale-max.jpg', $options_2);

/**
 * CROP METHOD IMAGE
 * jQuery plugin http://odyniec.net/projects/imgareaselect/
 */
$options_3 = array(
   
'type' => IMAGETYPE_JPEG,
   
'width' => 50,
   
'height' => 50,
   
'method' => THUMBNAIL_METHOD_CROP,
   
'coord_x1' => 80,
   
'coord_y1' => 100,
   
'coord_x2' => 130,
   
'coord_y2' => 150
);
Thumbnail::output($filename, $dir_save.'image-method-croping.jpg', $options_3);

/** SCALE MAX IMAGE AND CORNER WHITE(#FFFFFF) RADIUS 3 PX **/
$options_4 = array(
   
'type' => IMAGETYPE_JPEG,
   
'width' => 150,
   
'height' => 150,
   
'method' => THUMBNAIL_METHOD_SCALE_MAX,
   
'corcolor' => 'FFFFFF', // background color
   
'corner' => 3, // corner radius
);
Thumbnail::output($filename, $dir_save.'image-method-scale-max-corner.jpg', $options_4);

/** SCALE MAX IMAGE AND CORNER TRANSPARENT RADIUS 3 PX (PNG)**/
$options_5 = array(
   
'type' => IMAGETYPE_PNG,
   
'width' => 150,
   
'height' => 150,
   
'method' => THUMBNAIL_METHOD_SCALE_MAX,
   
'cortransparent' => 3, // corner trasparent radius
);
Thumbnail::output($filename, $dir_save.'image-method-scale-max-corner-transparent.png', $options_5);

/** SCALE MAX IMAGE, CORNER TRANSPARENT RADIUS 5 PX (PNG) AND WATERMARK (PNG) **/
$options_6 = array(
   
'type' => IMAGETYPE_PNG,
   
'width' => 150,
   
'height' => 150,
   
'method' => THUMBNAIL_METHOD_SCALE_MAX,
   
'cortransparent' => 5, // corner trasparent radius
   
'mark' => 5,
   
'mark-image' => $thumbnail
);
Thumbnail::output($filename, $dir_save.'image-method-scale-max-corner-transparent-watermark.png', $options_6);