WordPress.org

Forums

Jetpack by WordPress.com
[resolved] How to determine image width from attachment array with Photon? (10 posts)

  1. John Chandler
    Member
    Posted 2 years ago #

    I'm using Photon on a site that uses wp_get_attachment_image_src to pass the image along to a script which opens the image in a lightbox:

    $large = wp_get_attachment_image_src( $a->ID , 'gallery-large' );

    The image size is defined in functions this way, limiting the height to 600px, but allowing for whatever width is necessary:

    add_image_size('gallery-large', 9999, 600, false );

    In the code, I'm using <?php echo $large[0]; ?> to pass the image URL to the script, and Photon has properly taken that over. However, I'm also passing the actual width of the image to the script using <?php echo $large[2]; ?>. When Photon is deactivated, it works fine and returns the proper value. However, when Photon is activated, the width is not returned. Shouldn't this data still be stored in the DB and available to me to access? Is this a Photon bug, or is there another way I can determine the width?

    http://wordpress.org/extend/plugins/jetpack/

  2. Jeremy Herve
    Happiness Engineer
    Plugin Author

    Posted 2 years ago #

    Could you post a link to your site, so I can have a look at the issue? It would be useful to know the Photon image URL, as well as the original image URL that's built from your function.

    Thanks!

  3. John Chandler
    Member
    Posted 2 years ago #

    Jeremy,

    Here's an example of a gallery where it is occurring:

    http://theeverylastdetail.com/inspiration-gallery/?colors&id=748

    The issue occurs with the lightbox image when you click on a thumbnail.

    Here's a local image:
    http://theeverylastdetail.com/wp-content/uploads/2011/05/Vintage-orange-wedding-20.jpg

    Here's the photon image URL it's loading:
    http://i2.wp.com/theeverylastdetail.com/wp-content/uploads/2011/05/Vintage-orange-wedding-20.jpg?fit=9999%2C600

  4. Jeremy Herve
    Happiness Engineer
    Plugin Author

    Posted 2 years ago #

    Thanks.

    Could you try to update to Jetpack 2.1.2, and let me know if this helps?

  5. John Chandler
    Member
    Posted 2 years ago #

    Still the same issue after the update.

  6. Jeremy Herve
    Happiness Engineer
    Plugin Author

    Posted 2 years ago #

    Thanks for trying. We'll have a look at the issue into more detail, and I'll post again here as soon as we can address the issue.

  7. John Chandler
    Member
    Posted 2 years ago #

    Appreciate it

  8. Erick Hitter
    Code Wizard
    Plugin Author

    Posted 2 years ago #

    Hi John,

    The issue you reported is actually a necessary side effect of using Photon.

    At present, Photon has no way of informing WordPress of the dimensions of an image it resizes. While there are many cases where the size of the image received from Photon matches the requested size, there are also cases when this won't be true. This depends largely on the size of the original image and whether or not the image size dictates cropping be applied.

    As a result, the module sets WordPress' image functions to return false when an image is processed with Photon. This avoids image skewing and prevents WordPress from returning misinformation about the resized image.

    Hope this helps explain what's happening!

  9. John Chandler
    Member
    Posted 2 years ago #

    Erick,

    Thanks, that's helpful. Is there some kind of function I could use to bypass Photon in this one template?

    John

  10. Erick Hitter
    Code Wizard
    Plugin Author

    Posted 2 years ago #

    John,

    There is a jetpack_photon_override_image_downsize filter that, if you return true to, will bypass Photon for a specific image. The filter provides some information about the image requested as well, if that is useful to you. You should be able to construct some logic for use with that filter so that you bypass Photon for specific images, or on a given page.

    For reference, see http://plugins.trac.wordpress.org/browser/jetpack/trunk/class.photon.php?rev=664010#L335.

    Erick

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Jetpack by WordPress.com
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic