OOP Image Handling

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
allspiritseve
DevNet Resident
Posts: 1174
Joined: Thu Mar 06, 2008 8:23 am
Location: Ann Arbor, MI (USA)

Re: OOP Image Handling

Post by allspiritseve »

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)?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: OOP Image Handling

Post by onion2k »

Yep.
User avatar
allspiritseve
DevNet Resident
Posts: 1174
Joined: Thu Mar 06, 2008 8:23 am
Location: Ann Arbor, MI (USA)

Re: OOP Image Handling

Post by allspiritseve »

Onion2K, I am wondering why you opted for a (visitor? I'm not too familiar with those patterns) api for your php-image library?

Code: Select all

$image = new Image("image.jpg");
$image->attach(new image_fx_resize(200));
$image->imagePng();
I just opened photoshop, and looked at their Image menu. In PS style, you would maybe have an api like this:

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...
and then filters would be something like this:

Code: Select all

$image->attach (new Artistic::ColoredPencilFilter());
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...
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: OOP Image Handling

Post by onion2k »

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.
User avatar
allspiritseve
DevNet Resident
Posts: 1174
Joined: Thu Mar 06, 2008 8:23 am
Location: Ann Arbor, MI (USA)

Re: OOP Image Handling

Post by allspiritseve »

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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: OOP Image Handling

Post by onion2k »

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.
Post Reply