OOP Image Handling
Moderator: General Moderators
- allspiritseve
- DevNet Resident
- Posts: 1174
- Joined: Thu Mar 06, 2008 8:23 am
- Location: Ann Arbor, MI (USA)
Re: OOP Image Handling
Well, I'm not handling many photos right now, but I might in the future. So GD has things it does better than ImageMagick? (ie per-pixel effects)?
- allspiritseve
- DevNet Resident
- Posts: 1174
- Joined: Thu Mar 06, 2008 8:23 am
- Location: Ann Arbor, MI (USA)
Re: OOP Image Handling
Onion2K, I am wondering why you opted for a (visitor? I'm not too familiar with those patterns) api for your php-image library?
I just opened photoshop, and looked at their Image menu. In PS style, you would maybe have an api like this:
and then filters would be something like this:
Which is more like what your original methods look like. It just seems more logical to me to tell an image to resize itself, rather than applying a resize filter. But maybe that's because I've been using photoshop for 8 years...
Code: Select all
$image = new Image("image.jpg");
$image->attach(new image_fx_resize(200));
$image->imagePng();Code: Select all
$image->imageSize (200, 200); // I would prefer $image->resize (200, 200) but I'm just emulating photoshop's menu
$image->canvasSize (400, 400);
$image->crop (10,10, 20, 20);
etc...Code: Select all
$image->attach (new Artistic::ColoredPencilFilter());Re: OOP Image Handling
The ultimate aim is to use an autoloader to keep the memory footprint to a minimum. Rather than loading all the effect classes as it does now it'll only load what's used in the script. In Photoshop having everything in a monolithic app is fine, but in a PHP script with pretty limited memory you'll want to keep everything to a minimum - hence putting as little as possible in the base class.
- allspiritseve
- DevNet Resident
- Posts: 1174
- Joined: Thu Mar 06, 2008 8:23 am
- Location: Ann Arbor, MI (USA)
Re: OOP Image Handling
Well, I completely understand for filters-- attaching them seems like the best route. It just seems odd to me to attach a filter to resize or crop an image. Using the photoshop Image menu as a guide, there's probably only about 5-6 methods that would make sense to be added to the image class.
Re: OOP Image Handling
Exactly. There's lots of things to add, but most of them won't be used by most people. In order to keep the memory usage to an absolute minimum (thereby leaving as much as possible for the image itself) I want to keep the base class as empty as possible and put all the effects in plugins (resizing is just an effect).
If you feel differently you could easily move the stuff you think should be in the base class in to it. It'd be a pretty simple job.
If you feel differently you could easily move the stuff you think should be in the base class in to it. It'd be a pretty simple job.