PHP Classes

File: Example

Recommend this page to a friend!
  Classes of Daniele Pignedoli   Image Composer Batch Resizer   Example   Download  
File: Example
Role: Example script
Content type: text/plain
Description: The example usage
Class: Image Composer Batch Resizer
Process multiple images all at once
Author: By
Last change:
Date: 14 years ago
Size: 2,489 bytes
 

Contents

Class file image Download
<?php
/*
21/04/2009

ImageComposer resizer class, created by Daniele Pignedoli (daniele.pignedoli@gmail.com)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require_once('lib-img.php');
//initialize the batch
$myBatch = new ImageComposer();
//set the default background type, to use when the img specific background
//is not set
$myBatch->defaultBg = new BackgroundColor('#EDF3FE', 200, 200);
//add the first image
$first = $myBatch->addImage('first.jpg');
//crop the bigger portion of the image with ratio 1
//the ratio is intended as width / height
//so ratio 1 mean a square
$first->Crop(1);
//set the thumb size, binding the width dimension at 190 pixel,
//so the height dimension will depend by the image original height
$first->setThumbSize('w', 190);
//set the thumbs name..
$first->thName = 'thumb-01.jpg';
//and the path
$first->thPath = 'thumbs';

//add the second image
$second = $myBatch->addImage('second.jpg');
//set the thumb size, binding at the height
$second->setThumbSize('h', 190);
$second->thName = 'thumb-02.jpg';
$second->thPath = 'thumbs';
//set a image as background:
$second->bg = new BackgroundImage('background.jpg');
//to remove this image from the batch without process it,
//simply call $myBath->removeImage($second);

//add the third image
$third = $myBatch->addImage('third.jpg');
$third->setThumbSize('h', 190);
$third->thName = 'thumb-03.jpg';
$third->thPath = 'thumbs';
//set the background mode in 'simple': the thumb wont have any background,
//only resized keeping the aspect ratio.
$third->bg = 'simple';
//set the quality, default id 80.
$third->quality = 100;

//process alla the image in myBatch object.
$myBatch->Process();
echo
'<a href="' . $first->thUrl . '" target="_blank">first one</a><br />';
echo
'<a href="' . $second->thUrl . '" target="_blank">second</a><br />';
echo
'<a href="' . $third->thUrl . '" target="_blank">last one</a><br />';
?>