0

I know that when you upload an image to the Wordpress media library, it automatically creates some duplicates of that image in different sizes. I'd like to know how I can return those differently sized image files.

The solution I'm currently using is this:

<?php
$image = get_field('image');
$imageurl = $image ['url'];
?>

<img src="<?php echo str_replace(".jpg","-800x500.jpg",$imageurl); ?>">

This is fine, but I'm looking for a function native to wordpress that would do this. Like querying an array of these differently sized files of the same image.

Note that wp_get_attachment_image_src and functions like it are not what I'm looking for. Even though you can set a size to be returned, it doesn't change the file in question.

0

I'm not quite sure what data is in your get_field('image') but it sounds like you want all the metadata associated with an image. To do that just pass the $id to wp_get_attachment_metadata().

The result would be:

Array
   (
       [width] => 2400
       [height] => 1559
       [file] => 2011/12/press_image.jpg
       [sizes] => Array
           (
               [thumbnail] => Array
                   (
                       [file] => press_image-150x150.jpg
                       [width] => 150
                       [height] => 150
                       [mime-type] => image/jpeg
                   )
               [medium] => Array
                   (
                       [file] => press_image-4-300x194.jpg
                       [width] => 300
                       [height] => 194
                       [mime-type] => image/jpeg
                   )
               [large] => Array
                   (
                       [file] => press_image-1024x665.jpg
                       [width] => 1024
                       [height] => 665
                       [mime-type] => image/jpeg
                   )
               [post-thumbnail] => Array
                   (
                       [file] => press_image-624x405.jpg
                       [width] => 624
                       [height] => 405
                       [mime-type] => image/jpeg
                   )
           )
       [image_meta] => Array
           (
               [aperture] => 5
               [credit] => 
               [camera] => Canon EOS-1Ds Mark III
               [caption] => 
               [created_timestamp] => 1323190643
               [copyright] => 
               [focal_length] => 35
               [iso] => 800
               [shutter_speed] => 0.016666666666667
               [title] => 
           )
   )
  • great! thank you. this is exactly what I'm looking for. – r miller Feb 29 '16 at 21:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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