Hi guys, I need image functionality (thumbs and so) and I’m currently porting one Drupal interface for working with GD2, making a component that interfaces to it with the aim to build an implementation for ImageMagick too in a while
My first design is to make a component with generic methods, an Interface for the implementations and one implementation for GD2, do you have comments? Am I in right direction?
Here is the result (no testing yet, but as the code comes from Drupal I suppose it won’t have too many mistakes), just to be placed in compoments directory and ready to use…
Please I want critics… above all about architecture, I’m beginning with all of this of Components and Behaviours and although I’m in my first steps, I’d like to contribute
ok, I’m sorry because yesterday it was late and what I uploaded was a bunch of untested code with many mistakes… today I’ll upload the working version I use to build thumbnails using the strategy of “scale_and_crop” with the gd2 implementation… soon I’ll try to upload the ImageMagic version
the thing is my first aim was to focus on ImageCache strategy but I quitted because of performance… as you know ImageCache follows the strategy of letting php serving the image (cached and modified) based on some configuration, and from my tests the Apache serving the modified file directly is 4 or 5 times faster than php dumping the same file cached, so first of all I’m porting the core lib in front of GD and ImageMagic and later I’ll try to mount something like ImageCache
it’s soon to mount a project, I’ll try to send code for people to test, and later if the thing sounds interesting I’ll make the project
I think you’ve got it wrong that imagecache is serving images via php. Actually php is involved only in image resizing/filtering process that is triggered first time not yet existing image is requested. Resulting image is saved and then is serving directly without php. That’s if you’ve configured Drupal to use “public” files mode instead of serving them with php.
to print in the buffer marking it as image/jpeg or whatever it is…
that’s why I changed from Drupal to Yii, Drupal does a lot of things I want and I like but as a counterside, does even more I dont want at all, and for very custom webs, it’s really slow, above all in my case I was using ImageCache intensively, drawing in one page more or less 40/50 images through its filter, and the result was reeeeaaaaally sloooooow
for this reason I’m planning (I have a prototype) a library that GENERATE a cache of files, but files are served directly by Apache (I dont want php serving’em)
Basic explanation: you can create as many presets as you want, in this case I have created one named "thumbs"
that caches files in the dir "webroot / imagecache", and for this preset I added two actions: scaleAndCrop and
later rotate. Currently (look at the code) I support: resize, scale, scaleAndCrop, rotate and crop
For testing: create a controller and add for example this action:
public function actionFile() {
$thumb = Yii::app()->image->createUrl(
'thumbs', // the preset we have configurated
YiiBase::getPathOfAlias('webroot.files').'/X TRILE1.JPG'); // An image file!!!
if ($thumb) print '<img src="'.$thumb.'" alt=""/>';
else print "bad";
}
Invoke your action:
first time, the api will create the image and caches in the specified dir
rest, simply returns the cached images so… it’s very fast
thx to both for your comments… I’ll take a time to improve the library and after thinking the weekend (spent the whole sunday with a big hangover because of that ), I’ll implement the three ways to access the component:
tradicional library: that is calling the methods, as any class lib
defining presets at app config and calling for createUrl/Path giving the preset and putting the result image in an img tag, in that definition will come the operations over the image, the path to save them, etc
as samdark asked, I’ll implement the ImageCache strategy, programming an Action that based on some parameter (preset) will return the image with the preset applied
on the other hand, I’ll implement ImageMagik and of course “purgue” for the caches, lastly, I’ll add more operations for using with presets
anyway… keep in mind that this is a first release so… be patient! (and thanks for testing)
It’d be great to see the functionality from the Drupal module imagecache_actions too - it has some nice extras such as watermarking, text overlays etc.
2011/09/18 15:40:11 [error] [php] imagecolorsforindex() [<a href=‘function.imagecolorsforindex’>function.imagecolorsforindex</a>]: Color index 99 out of range (C:\xampp\htdocs\protected\extensions\imageapi\GDToolkit.php:106)