• Resolved kevleitch

    (@kevleitch)


    Hi,

    Great plugin, thank you ??

    I understand that in the latest versions of this plugin you can output both cropped and original versions of the image. I have an ACF called upload_artwork (image with user-crop type) which, when someone uploads their image, they are forced to crop it immediately. This works fine.

    I can get the cropped version of the image using a return value of image URL like so:

    the_field('upload_artwork');

    My question is, what code do I need to output the image URL of the original image. I know its possible as I’ve read through the Support forum but I just don’t know what code I need to use to reference the original image.

    Thanks ??

    https://www.ads-software.com/plugins/acf-image-crop-add-on/

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author andersthorborg

    (@andersthorborg)

    To access the original image, you need to have Image Array as return type. In that array you’ll have access all the data you need:

    Example array:

    Array
    (
        [id] => 247
        [alt] =>
        [title] => 7K0A0223_300x300_acf_cropped3
        [caption] =>
        [description] =>
        [mime_type] => image/jpeg
        [url] => https://localhost/acf-crop/wp-content/uploads/2014/09/7K0A0223_300x300_acf_cropped3.jpg
        [width] => 300
        [height] => 300
        [sizes] => Array
            (
                [thumbnail] => https://localhost/acf-crop/wp-content/uploads/2014/09/7K0A0223_300x300_acf_cropped3-150x150.jpg
                [thumbnail-width] => 150
                [thumbnail-height] => 150
                [medium] => https://localhost/acf-crop/wp-content/uploads/2014/09/7K0A0223_300x300_acf_cropped3.jpg
                [medium-width] => 300
                [medium-height] => 300
                [large] => https://localhost/acf-crop/wp-content/uploads/2014/09/7K0A0223_300x300_acf_cropped3.jpg
                [large-width] => 300
                [large-height] => 300
                ...more sizes
            )
    
        [original_image] => Array
            (
                [id] => 5
                [alt] =>
                [title] => 7adsasdas
                [caption] =>
                [description] =>
                [mime_type] => image/jpeg
                [url] => https://localhost/acf-crop/wp-content/uploads/2014/01/7K0A0223.jpg
                [width] => 2000
                [height] => 1333
                [sizes] => Array
                    (
                        [thumbnail] => https://localhost/acf-crop/wp-content/uploads/2014/01/7K0A0223-150x150.jpg
                        [thumbnail-width] => 150
                        [thumbnail-height] => 150
                        [medium] => https://localhost/acf-crop/wp-content/uploads/2014/01/7K0A0223-300x199.jpg
                        [medium-width] => 300
                        [medium-height] => 199
                        [large] => https://localhost/acf-crop/wp-content/uploads/2014/01/7K0A0223-1024x682.jpg
                        [large-width] => 474
                        [large-height] => 315
                       ... more sizes
                    )
    
            )
    
    )

    Thus you could use something like:

    // Get the image array
    $image = get_field('my_image');
    
    // Retrieve URL of cropped image
    $cropped_url = $image['url'];
    
    // Retrieve URL of original image
    $original_url = $image['original_image']['url'];

    Hope that clears it up.

    Best,
    Anders

    Is there updated code that produces the “original_image” data?
    I followed your directions but there is no $image[‘original_image’] in my image object.

    Plugin Author andersthorborg

    (@andersthorborg)

    What ACF version are you using?

    Version 4.3.9

    Thread Starter kevleitch

    (@kevleitch)

    Hi,

    As far as I can see, ACF doesn’t support a return type of Image Array as per this screengrab:

    https://dl.dropboxusercontent.com/u/167786/imagetype.png

    I’m not sure why this is set as [resolved].

    Same problem here, using the plugin ver 1.4.1 and ACF 4.3.9.

    Array is not displayed as an option and it’s neither included in acf-image-crop-v4.php. Just ‘url’ ‘id’ and ‘object’.

    Was it removed due some problem?

    Thread Starter kevleitch

    (@kevleitch)

    I also don’t know why this has been marked as resolved when it clearly isn’t.

    Quick fix/workaround:

    I did some peaking in the DB, seems the field saves a meta that contains 2 things, original image ID and Cropped image ID. After that, depending on how you configure it (object or url or id), it process then to return either just the ID from the db or fetch requested info.

    So I cam up with the ‘dirtiest/quickest’ way to workaround, make it return the same object that is saved to DB containing only both ids.

    To do this:

    1- Add another return option, in ver. 4.3.9 this would be in line 274, change:

    'choices'	=> array(
    				'url'		=>	__("Image URL",'acf'),
    				'id'		=>	__("Image ID",'acf'),
    				'object'	=>	__("Image Object",'acf')
    			),

    to:

    'choices'	=> array(
    				'url'		=>	__("Image URL",'acf'),
    				'id'		=>	__("Image ID",'acf'),
    				'object'	=>	__("Image Object",'acf'),
    				'original_object'	=>	__("Original Object (Original+Cropped)",'acf')
    			),

    2- The ‘built of returns’ is just a series of if else, so in line 528 add another ifelse for the new option:

    if( $field['save_format'] == 'original_object' ){
    			$value = $data;
    		}

    This will make the plugin return a std class object containing the 2 images ids, example:

    stdClass Object
    (
        [original_image] => 110
        [cropped_image] => 135
    )
    Kay

    (@kayheunen)

    Faster Quick fix.

    Just add this after line 474

    $value['original_image'] = $this->getImageArray($data->original_image);
    Thread Starter kevleitch

    (@kevleitch)

    Thanks Kayheunen ??

    Not being great with array manipulations, what PHP do I need to add to my template to display the original image?

    Kay

    (@kayheunen)

    It’s the same array as the cropped image, only in key ‘original_image’.

    // Get the image array
    $image = get_field('my_image');
    
    // Retrieve URL of cropped image
    $cropped_url = $image['url'];
    
    // Retrieve URL of original image
    $original_url = $image['original_image']['url'];

    Thread Starter kevleitch

    (@kevleitch)

    Awesome, thank you very much ??

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Getting link to original image?’ is closed to new replies.