Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have the following code in my theme:

<?php
$size = 'large';
$postimage = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), $size );
$url = $postimage[0];
$h = $postimage[2]
?>

<div style="background-image: url(<?php echo $url; ?>); height: <?php echo $h; ?>;"></div>

Here's an example var_dump output for $postimage:

array(3) {
 [0]=> string(99) "{base url here}/uploads/2013/10/h3greendeck.jpg?fit=660%2C660"
 [1]=> bool(false)
 [2]=> bool(false)
}

If I remove the size argument for wp_get_attachment_image_src() to let it use default I get the same result. Why is size returning boolean, when WordPress knows the size of the image? This happens for every single instance of this code, regardless of the post I'm viewing.

share|improve this question
1  
That fit= argument is not something I recognize. I have to assume there is a plugin involved, or a theme. Disable your plugins and switch to a bundled theme. Do you still have this problem? –  s_ha_dum Apr 9 at 14:37
    
Seems that some code, probably a plugin, is filtering wp_get_attachment_image_src to append that 'fit' query variable and possibly same code is the culprit of this weird behavior –  G. M. Apr 9 at 15:47

1 Answer 1

up vote 4 down vote accepted

This sounds like a description of the JetPack's Photon service.

Photon is an image acceleration and modification service for Jetpack-connected WordPress sites. Converted images are cached automatically and served from the WordPress.com CDN. Images can be cropped, resized, and filtered by using a simple API controlled by GET query arguments. When Photon is enabled in Jetpack, images are updated on the fly.

The Photon API includes the fit GET parameter:

http://i0.wp.com/example.com/wp-content/uploads/2014/04/abc.jpg?fit=600%2C400

where %2C is url encoded comma.

It uses the image_downsize filter to overwrite the image retrevial with:

// Generate Photon URL
$image = array(
    jetpack_photon_url( $image_url, $photon_args ),
    false,
    false
);

where the width and height are set to false.

share|improve this answer
1  
That was the problem, thanks! Disabling Photon gave me valid dimensions. –  Christiaan Apr 9 at 17:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.