July 2, 201511 yr I'm really struggling with this. I'm basically trying to set some resizing on images, using the ACF image field. I want it so that when a client uploads an image, it resizes the image to certain dimensions. Then I can just output a tag in my template where the image needs to appear. Does anyone know how this i possible, and if it is in WP? This site is really image heavy and I don't want clients adding in original size images. If there's an alternative then let me know. I need something to help with this problem. Thanks
July 2, 201511 yr I saw your other post, but wasn't sure what you needed. Don't know about ACE, but would it help if you set custom thumbnail size, in your functions.php, like this: add_image_size( 'your-new-size-ref', 1168, 500, true ); true or false for hard crop or not. Is that what you need?
July 2, 201511 yr Then you retrieve it with: the_post_thumbnail('your-new-size-ref'); Edited July 2, 201511 yr by teodora
July 2, 201511 yr Author I got as far as adding some custom sizes into the functions.php file. There's a few differences between the ACF implementation though, it uses <?php the_field('field_name'); ?> instead. I'm looking to do basically the same thing, but with ACF.
July 2, 201511 yr Hi, The way I do it is to make sure the field returns the image object. Then use the code below in your template $imagefield = get_field('image_field_name'); $imageid = $imagefield['id']; $image = wp_get_attachment_image_src($imageid,'large'); Replacing the 'large' with thumbnail/medium/large/full, or your custom name for an image size created in your functions. You can then output the image url with: echo $image[0]; Hope it helps!
July 2, 201511 yr Some links : https://wordpress.org/support/topic/plugin-advanced-custom-fields-display-custom-image-size http://www.advancedcustomfields.com/resources/image/ I don't use ACE, unfortunately, so hope that would help.
July 2, 201511 yr Author Thanks Mike, that worked perfectly.I'm guessing for every instance of this I'll have setup these variables again? <?php $imagefield = get_field('image_full'); $imageid = $imagefield['id']; $image = wp_get_attachment_image_src($imageid,'full'); $imagefield2 = get_field('image_med'); $imageid2 = $imagefield2['id']; $image2 = wp_get_attachment_image_src($imageid2,'medium'); ?>
July 2, 201511 yr Author Some links : https://wordpress.org/support/topic/plugin-advanced-custom-fields-display-custom-image-size http://www.advancedcustomfields.com/resources/image/ I don't use ACE, unfortunately, so hope that would help. I was so close, but I was trying to do this off the URL return type instead of the object or ID. Still, it could be cleaner. I'm hoping one day someone ports this to WP http://glide.thephpleague.com/0.3/api/size/.
July 2, 201511 yr Agreed, could be cleaner... Easiest (at least for me) is to set up a new instance for each image. Or you could set up variables for the field and size and somehow simplify the whole thing with some conditional logic? Just on top of my head, I guess that's how I would do it if needed to output lots of images. Still ugly, though. Glide looks good, I should imagine it wouldn't be too difficult to integrate with WP.
July 2, 201511 yr Author Agreed, could be cleaner... Easiest (at least for me) is to set up a new instance for each image. Or you could set up variables for the field and size and somehow simplify the whole thing with some conditional logic? Just on top of my head, I guess that's how I would do it if needed to output lots of images. Still ugly, though. Glide looks good, I should imagine it wouldn't be too difficult to integrate with WP. I wouldn't know where to start creating a Glide plugin, I'd imagine it would be popular though. Statamic V2 is using it, you can see a video in action here http://talonsbeard.com/transform.
Create an account or sign in to comment