0

My question is about image sizing. I get how to the sizing/cropping stuff natively in WP

add_image_size( 'thumb-crazy', 500,500, true);

And then in the template type:

if ( has_post_thumbnail() ) {
the_post_thumbnail('thumb-crazy'); //This images get dimensions 500x500.
} 

But I'm struggling how to set which image-sizes to use for ACF-plugin:

When I put this in functions.php

add_image_size( 'thumb-crazy', 500,500, true);

I select thumb-crazy from the attributes of the image-field. (It doesn't to do any crop at all or some totally other dimensions)

$image = get_field('image_personnel');
$size = 'thumb-crazy';
echo wp_get_attachment_image( $image, $size );

It doesn't have the effect that the image is 500x500 cropped. Why? Is this an issue with the plugin or am I missing something?

  • the only size attribute you can select when creating the image field in ACF has nothing to do with the front end, it's the size you see in the admin interface when interacting with that field. your code should work fine if Return Value for the field is set to Image ID, but note that image sizes are only generated during upload. if you've added or changed the size after uploading the file, you won't see the correct size. – Milo Apr 24 '14 at 21:49
  • Ok. So you're saying it's not possible to create own sizes with ACF ? (It must be one of the sizes in the admin panel?) – bestprogrammerintheworld Apr 24 '14 at 21:56
  • you can use any of the built in sizes or those added via add_image_size, I was just commenting on your statement "I select thumb-crazy from the attributes of the image-field", which has nothing to do with front end output. all ACF does is store the attachment ID, everything else works identically to the WordPress API regarding images and sizes. – Milo Apr 24 '14 at 22:06
  • Ok. Forgive me for being a little vague. I understand that is just which thumbnail that is shown in the preview (and has nothing to with frontend). But not even that works. – bestprogrammerintheworld Apr 24 '14 at 22:14
  • was the image uploaded after you added the new image size? – Milo Apr 24 '14 at 22:18
1

Obviosuly... I WAS missing something. I uploaded pictures that hade smaller dimensions then specified in the customized image sizes and they wouldn't scale up. Images with 500x500 or higher works fine, but if I upload an image width 200x300 it won't work as expected. This issue is not so well documented in the codex.

  • You have to use CSS to fight those conditions. Something like: .example-div img {width: 100%; height: auto; min-height: 500px;} where your .example-div must contain a width at least. – Mayeenul Islam Apr 25 '14 at 3:06
  • yes, I COULD do that. But that totally messes up design. I would go for manually enlarging images to a specific size and then upload those images. – bestprogrammerintheworld Apr 25 '14 at 9:08

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.