Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

ACF and image manipulation

Featured Replies

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 :)

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?

  • 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.

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!
  • 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');
?>
  • Author

 

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/.

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.

  • 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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.