Home › Forums › Add-ons › Repeater Field › Custom Image Size without Cropping › Reply To: Custom Image Size without Cropping
Maybe we can help each other on this one? I’ve been working on something similar with no luck.
I got so far as creating a custom image size by adding something like this to the functions.php file:
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'homepage-thumb', 97, 83, true ); /* 97px wide by 83px tall */
}
add_filter( 'image_size_names_choose', 'my_custom_sizes' );
function my_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'homepage-thumb' => __('Homepage Thumbnail'),
) );
}
Replacing homepage-thumb with the name of your custom thumbnail size. Where it says “true” that just uses a soft proportional crop, instead of a hard crop. If you changed that to “false” it will create a new separate image file when you upload, rather than just resizing the original image to those proportions.
The problem I’m having, is the code to use that image isn’t working. I can’t even get it to show the default thumbnail size. I tried using your code above, like this:
<img src="<?php $homethumb = the_field('button_one_image'); echo $homethumb['sizes']['homepage-thumb']; ?>" />
I don’t know what I’m doing wrong though, I must be missing something.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.