WordPress.org

Ready to get started?Download WordPress

Forums

EWWW Image Optimizer
[resolved] Calling Function Manually (5 posts)

  1. styledev
    Member
    Posted 1 year ago #

    I am using https://github.com/matthewruddy/wordpress-timthumb-alternative/ and I wanted to know if there is an easy way to integrate the ewww optimization to work with this resize tool.

    It uses the new "wp_image_editor" class and I did see your TODO noting integrating into this. Any idea when you could get around to this because it would bring me to 100/100 pagespeed score!

    Thanks and much appreciated!

    http://wordpress.org/extend/plugins/ewww-image-optimizer/

  2. nosilver4u
    Member
    Plugin Author

    Posted 1 year ago #

    it's going to be a while (if ever), since I'm in the middle of expanding support to Windows & FreeBSD, and I've not seen the documentation for creating a new wp_image_editor class yet. At any rate, EWWW IO works with the existing Worpdress resize functions by running when the metadata is updated, so I'm curious to see why/if the one you are using skips that step. Generally, any resize operation (at least using the default WP method) creates a file with a new name, which requires calling the function to update metadata, which is where I've hooked into.

    All that to say, it SHOULD already work. If it doesn't, that is quite strange.

  3. styledev
    Member
    Posted 1 year ago #

    Interesting, can you point me to the best place to throw in an output to see when it runs? Something like echo "I am running"; exit();?

    Documentation: http://codex.wordpress.org/Class_Reference/WP_Image_Editor

    Maybe it is running, but PageSpeed is kicking the new images back saying they need to be optimized by about 4% each. You can see below that wp_update_attachment_metadata does get called.

    ...

    $editor->crop( $src_x, $src_y, $src_w, $src_h, $dest_width, $dest_height );
    $saved = $editor->save( $dest_file_name );
    // Add the resized dimensions to original image metadata (so we can delete our resized images when the original image is delete from the Media Library)
    $metadata = wp_get_attachment_metadata( $get_attachment[0]->ID );
    if ( isset( $metadata['image_meta'] ) ) {
    	$metadata['image_meta']['resized_images'][] = $resized_width .'x'. $resized_height;
    	wp_update_attachment_metadata( $get_attachment[0]->ID, $metadata );
    }

    ...

  4. styledev
    Member
    Posted 1 year ago #

    Here is a link to the core file that handles the ->save above:

    http://core.trac.wordpress.org/browser/trunk/wp-includes/class-wp-image-editor-imagick.php

  5. nosilver4u
    Member
    Plugin Author

    Posted 1 year ago #

    You could put that somewhere around line 787 in ewww-image-optimizer.php
    The ewww_image_optimizer() function gets called anytime an optimize is called for (on a resize, upload, bulk action, etc.), and that would let you know if the hook is working.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.