Support » Plugins » Hacks » extending wp_image_editor

  • Resolved nosilver4u

    (@nosilver4u)


    Two questions:

    1. Is it possible to extend the wp_image_editor class directly instead of extending the ‘implementations’ like gd or imagick? All the stuff I’ve seen on this so far seems to indicate that you have to choose an implementation to extend, which makes sense sometimes. For example, a video I watched did a sepia filter, which is obviously going to operate differently in GD than Imagick (or GMagick). However, what my plugin is going to do doesn’t depend on either of those specifically and should be ‘library agnostic’.

    2. Is there any documentation regarding extending the class as opposed to just using the class. Related to #1, I want to let GD/Imagick/GMagick do all the image manipulation, and then essentially run the result through an optimization ‘filter’.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m no expert on image handling, but WP_Image_Editor itself doesn’t do much, it’s an empty framework. In order to do something with an image, you need to pick an implementation so that the interface is properly defined.

    Maybe I don’t know what I’m talking about, but could you create a singleton class that, based on some criteria, selects an implementation, creates an image editor object from that selection and interfaces with that? So instead of being library agnostic, it is pan-theistic, so to speak.

    I don’t know of any documentation, otherwise I could speak more intelligently on this.

    Thread Starter nosilver4u

    (@nosilver4u)

    I started digging through the wp_image_editor code last night, and I think you’re right on with #1. I’m still learning how to work with classes, so my learning curve is pretty steep here.

    On #2, if anyone has any pointers to more examples or documentation as to how to just extend the GD & Imagick classes, that would be appreciated.

    Thread Starter nosilver4u

    (@nosilver4u)

    So, here’s what I did, and I’m finding some odd behavior…
    Just for starters, I extended WP_Image_Editor_GD with a single method to replace the _save function/method. I added some debugging code, and noticed that it appeared to be processing each image multiple times.

    So, I disabled my editor class, and added the debugging code right into the GD _save method, and discovered that WP appears to be generating the resize images multiple times.

    I definitely don’t want to optimize an image multiple times, as this would put excessive load on the server. Is there someone that can shed some light on this? Why is WP regenerating the resizes multiple times, and can this be fixed?

    code is in the dev version of http://wordpress.org/plugins/ewww-image-optimizer/

    UPDATE: might have figured it out, stay tuned…

    Thread Starter nosilver4u

    (@nosilver4u)

    Yup, it was my debug log function that was getting called multiple times, not the wp_image_editor class, doh!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘extending wp_image_editor’ is closed to new replies.