Re: RFI: Image_Resize
| From: | Alan Knowles | Date: | Mon, 15 Apr 2002 06:35:08 +0000 |
| Subject: | Re: RFI: Image_Resize | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-5495@lists.php.net to get a copy of this message | ||
started playing with this - probably will continue today - I've got 2 projects + phpmole that needs this stuff....
I suggest moving the resize calculations stuff to the Image_Resize class, as its generic on all classes
also passing an option array to the startup eg. (is that a pear standard - or is it just used alot)...
$img =Image_Resize::start(array(
'image_lib'=>'IM',
'IM_path'=>'/home/me/bin/imagick/'
));
$img->load(....)
$img->ResizeY(1024);
$img->save(...);
It would be nice/easy to add rotate, but that kind of ruins the name of the class :)
anyway just my 2c :)
regards alan
--- snipped from image.php ----
var $options=array(); //associative array of options
/* valid options are
image_lib => GD (libgd), IM (image magic command line), Imagick(imagick extension)
IM_path =>(imagemagic path);
*/
/**
* setup
*
*/
function setup($options)
{
include_once "Image_Resize/Image_".$options['image_lib'].php" ;
$classname = "Image_Resize_${image_lib}";
if (!class_exists($classname)) {
return PEAR::raiseError(null, "Cannot find class $classname",
null, null, null, 'Image_Resize_Error', true);
}
$obj =& new $classname($options);;
return $obj;
} // End setup
function ResizeX($new_x) {
$this->new_x = (int) $new_x;
$this->new_y = (int) (($new_x / $this->img_x) * $this->img_y);
}
/**
* ResizeY - max Y
*
*/
function ResizeY($new_x) {
$this->new_y = $new_x;
$this->new_x = (int) (($new_y / $this->img_y) * $this->img_x);
}
/**
* resize
*
*/
function resize($new_x, $new_y='') {
$this->new_x = $new_x;
$this->new_y = $new_y;
if ($new_y === '')
$this->ResizeX($new_x);
$this->_resize();
}
/**
* REALLY resize
*
*/
function _resize() {
return PEAR::raiseError(null, "No Resize method exists",
null, null, null, 'Image_Resize_Error', true);
}
}
/**
* scale
*
*/
function scale($size) {
if ($this->img_x >= $this->img_y) {
$this->ResizeX($size);
} else {
$this->ResizeY($size);
}
$this->_resize();
} // End scale
/**
* REALLY resize
*
*/
function _resize() {
return PEAR::raiseError(null, "No Resize method exists",
null, null, null, 'Image_Resize_Error', true);
}
}
Peter Bowyer wrote:
Hi, I've written a package called Image_Resize that I'd like considered for inclusion into PEAR. The code provides a generic interface to the image manipulation libraries. Currently it supports GD and ImageMagick, but can easily be extended for other libraries. So far only basic functions like scaling the images are supported, hence the package name. I have not decided whether the feature set should be expanded (to include image rotation, text on image etc...) or not, but if it is then I guess that this package name isn't suitable. The code can be found @ <http://www.narrow-gauge.co.uk/Image_Resize.tar.gz>. It is currently undocumented and needs better error handling, but it works and should allow you to see what/how the package works. This will be improved before it's admitted to PEAR. Comments? Peter. -- Maple Design - quality web design and programming http://www.mapledesign.co.uk