Jump to content

Module: ImageSizerExtended


Oliver
 Share

Recommended Posts

In a current project it became necessary to implement more extended image manipulation functionalities as I needed to fix image orientation of photos where the orientation data was just stored in images's exif data set.

As it was just one more manipulation among several other's the ImageSizer was already taking care of, I thought it would be nice to be able to extend the native ImageSizer class by individual methods. But as I - of course - didn't want to change core files and the ImageSizer itself isn't a “module” that seemed hard to achieve. But after I did some research, I found a solution using an instance of ImageSizer encapsuled within a module using magic methods to direct native method calls to the ImageSizer while providing extended methods from the module itself.

It's far from perfect. The code is still messy and I just added methods to check for orientation data, fix orientation and therefor of course image rotation and flipping. Haven't been testing everything yet, but I uploaded the module to github. Could be useful as a starting point.

https://github.com/o...geSizerExtended

It is used the same way as the original ImageSizer:

$sizer = new ImageSizerExtended($path);
$sizer->method();
  • Like 2
Link to comment
Share on other sites

Nice work Oliver! I like the approach you've taken with delegating to PW's image sizer with magic methods. PW's ImageSizer class actually isn't hookable, but I could certainly make it that way if you would prefer to add methods to PW's ImageSizer. However, I'm not sure that it matters, as the approach you have here is probably better.

In your module settings, I would suggest setting both singular and autoload to false.

The only other thing I can think of is that it would be nice to have constants or functions to relate to the available orientations. So someone could do this:

$sizer->fixOrientation(ImageSizerExtended::flipHorizontal);

Or better yet:

$sizer->flipHorizontal();
Link to comment
Share on other sites

Thanks for the feedback.

Ryan, using constants is a nice idea. I'll implement that as soon as I find the time.

Regarding hookable methods: I don't think making the native ImageSizer methods hookable is necessary. But maybe I should make them and the extendes one's hookable through the module?

Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...