Code Monkey home page Code Monkey logo

acf-image-crop's Introduction

Advanced Custom Fields: Image Crop Add-on

Contributors: andersthorborg Tags: afc, advanced custom fields, image crop, image, crop Requires at least: 3.5 Tested up to: 4.6 Stable tag: 1.4.12 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html

An image field making it possible/required for the user to crop the selected image to the specified image size or dimensions

Description

ACF image crop is an extended version of the native Image-field in ACF. The field gives the developer/administrator the option to predefine a size for the image, which the user is prompted to crop on the various edit screens. This solves the common issue of images being cropped inappropriately by the automated center-crop, that wordpress performs.

The plugin supports the defined image sizes as well as a custom option, enabling the developer to specify the dimensions from within the field edit screen.

The field can be configured to enforce a hard crop or a minimal-dimension-based crop. The hard crop will lock the aspect ratio of the crop where as the minimal-dimension-based crop will not allow the user to crop the image below the specified dimensions.

This plugin diverts from plugins like Manual Image Crop in that when the user crops an image, a new attachment is generated, so that the relevant crop only applies in the context it is edited. It also keeps the user from dealing with the concept of various image sizes.

As of version 1.0 the field can be configured to either create the cropped image as a media-item (the default behavior) or simply create it and refer directly to the file without adding it to the media library. This will prevent the media library from being cluttered with several cropped versions of the same image. When this option is selected the only available return type for the field is URL.

Compatibility

This add-on will work with:

  • version 4 and up

Installation

This add-on can be treated as both a WP plugin and a theme include.

Plugin

  1. Copy the 'acf-image_crop' folder into your plugins folder
  2. Activate the plugin via the Plugins admin page

Include

  1. Copy the 'acf-image_crop' folder into your theme folder (can use sub folders). You can place the folder anywhere inside the 'wp-content' directory
  2. Edit your functions.php file and add the code below (Make sure the path is correct to include the acf-image_crop.php file)

` add_action('acf/register_fields', 'my_register_fields');

function my_register_fields() { include_once('acf-image-crop/acf-image-crop.php'); } `

Screenshots

  1. Use a registered image size as the field target size
  2. Or use custom dimensions on the fly
  3. On the edit screen, select/upload an image as usual
  4. A crop-button will appear beneath the image (If desired, use the "Force user crop"-option to initialize the crop as soon as the user selects the image)
  5. The image is cropped to the desired format, using the restrictions set under field options
  6. The new format is shown using the specified preview size. The original image is kept with the field, so the image can be re-cropped at any time.

Changelog

1.4.12

  • Fix compatibility with ACF Pro 5.6.0

1.4.11

  • Address issue with changed ACF Pro validation behavior causing php warnings when saving fields

1.4.10

  • Add compatibility with ACF Pro 5.5.5

1.4.9

  • Use acf-image-crop/filename_postfix to allow custom filename postfixes

1.4.8

  • Fix button styling
  • Prevent php warnings for unset field settings

1.4.7

  • Added compatibility with ACF PRO 5.4.2.2 icons

1.4.6

  • Added compatibility with ACF 4.4.2 and ACF PRO 5.2.9

1.4.5

  • Added compatibility with ACF 5.2.7
  • Added image quality filter (needs testing)

1.4.4

  • Fixed migration from image field to not only return image ID
  • Fixed a js error in field settings caused by a change in class names in ACF

1.4.3

  • Removed unused assets

1.4.2

  • Improved migration from standard field to ACF crop field
  • Fixed and issue that caused warnings when options was not set
  • Fixed crop preview not showing correct crop position in some browsers
  • Improved error handling when server setup does not support image handling
  • Fixed original image data missing when saving to media library in v4
  • Improved error handling in v4

1.4.1

  • Fixed issue with image not cropping in v4

1.4

  • Fixed images with dot in the file name resulting in odd cropped image names
  • Fixed issues with php notices in v4
  • Fixed issues with broken image fields in v4
  • Temporarily fixed images smaller than preview size not being added (ACF bug)
  • Updated localization thanks to @tmconnect
  • Various tweaks and fixes by @tmconnect

1.3

  • Updated to be compatible with original image field changes as of ACF Pro 5.0.8. IMPORTANT: As this is a quick fix to ensure compatability with the newest ACF PRO version it is not backwards compatible. If you are using ACF Pro 5.0.7 and below, please use version 1.2 of this add-on.

1.2

  • Improved: Edit image is now working for most cropped image fields.
  • Fix: Wrong GUID for generated images that could cause issues when moving a site to a new location
  • Tweak: Added "original_image"-attribute when using return type "Object", containing the original image data.
  • Tweak: Return type "Object" is now available when not saving cropped image to media library. The data except from url, width and height is fetched from the original image.
  • Feature: It is now possible to hide cropped images from the media dialog. (See the new settings section) NB.: Only works for future cropped images.
  • Feature: Retina-mode, that makes the image field require and crop double the dimensions. Results in better integration with plugins like WP Retina 2x
  • Feature: Settings-seciton under Settings -> Media. Here you can choose to hide cropped images from the media dialog as well as enable/disable global retina mode.

1.1.4

  • Fixed an issue causing a php warning when editing custom fields
  • Fixed a js-issue causing image-crop-field hiding all subfields when editing repeater-/flexible content-fields

1.1.3

  • Fixed another issue with save to media option

1.1.2

  • Fixed issue with force crop option
  • Fixed issue with save to media option
  • Fixed issue with return type object

1.1.1

  • Removed unsued references and that caused php warnings
  • Added a missing default value that caused a php warning

1.1

  • Added ACF5 compatibility.
  • Please report any compatibility issues. As this has been an urgent feature request I have not had as much time for testing as I would have liked.

1.0

  • Added option to save the image to media library or refer directly to the created image, not using the media library.
  • Added better compatibility with the native image field making it possible to migrate from the regular image field to the crop-image field without losing the images currently attached. (It doesn't work the other way around)

0.8

  • Fixed an issue resulting in a black image, when image was cropped without moving the crop handles

0.7

  • Fixed return types other than image id causing fatal error

0.6

  • Fix for WP installs with non-standard folder structures

0.5

  • Initial Release.

acf-image-crop's People

Contributors

andersthorborg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

acf-image-crop's Issues

Returning black image

Hello, your plugin is very useful, thank you!
But I have a problem when I crop the image, it is returned all black.

*Sorry for the bad english x)

captura de tela 2014-02-28 as 11 51 58 1

Large pic field images have been scaled down automatically to 678x300px

There's a problem with the large image fields (in our case, 1800x600px) after the newest WP update.

Screen 1. The image uploaded has/had the right size of 1800x600px. It looks pixelated on the front-end now.
Screen 2. Upon opening one can see the image was somehow resized to the small image field size (678x300px)
3. If try to change the image to a big one from WP Gallery - downsized again.

Please fix, thanks

1 zoomin previev of the uploaded image
2 upon openiung the image

Full size crop

Hi there,

If i upload a 1920x1080 image and my crop for example is 735x400 i notice that the cut is always on the top left corner. Is it possible to make this always max centered? In 90% of the user cases people will want to get a wide as possible view.

great work so far 👍 hope you hear from you :)
Paul

Overlay modal not appearing correctly after WordPress 4.2.2 upgrade.

It seems since upgrading to the latest WordPress (4.22) and latest version of ACF the cropper appears inline rather that in an overlay modal. The dark overlay sits over the top of everything, so the tool becomes useless and inaccessible.

I think this requires an urgent fix?

screen shot 2015-07-14 at 12 27 18 am

Image attachment details not working

When trying to edit an image with user crop selected in the acf field options, the Image attachment details section fields are set as readonly. We tried to fix this with a js hack but it doesn't work as details are not saved. Any ideas?

fix for missing metadata in cropped image

in the cropped image the description, caption and alt metadata ist lost.

find

 // Get the filetype
                $wp_filetype = wp_check_filetype(basename($targetFilePath), null );
                $attachment = array(

before this get the date as vars:

$originalFileObject = get_post($id);
$originalFileDescription = $originalFileObject->post_content;
$originalFileCaption = $originalFileObject->post_excerpt;
$originalFileAlt = $originalFileObject->_wp_attachment_image_alt;

the change the array:

$attachment = array(
                     'guid' => $mediaDir['url'] . '/' . basename($targetFilePath),
                     'post_mime_type' => $wp_filetype['type'],
                     'post_title' => preg_replace('/\.[^.]+$/', '', basename($targetFilePath)),
                     'post_content' => $originalFileDescription, // new!
                     'post_excerpt' => $originalFileCaption,	// new!
                     'post_status' => 'inherit'
                );

and after this add the alt to the new file:
update_post_meta( $attachmentId, '_wp_attachment_image_alt', $originalFileAlt );

Doesn't work correctly with ACF Pro 5.2.7

I'm using your plugin in a frontend form and it's been working great. Unforunately it doesn't with the latest version of ACF Pro.

The issues I'm facing:

  1. the cropped version as well as the original size shows in the field inside the form
  2. the crop button is doubled
  3. when I hit one of the crop buttons an empty overlay shows up

Edit and Remove buttons

The edit and remove buttons are no longer working with Version 5.3.2.1 of ACF Pro.

Just need data-name="edit-button" and data-name="remove-button" "button" removed and it works again.

Fatal error

If I set Return Value to anything except “Image ID” I get this error:

Fatal error: Cannot use object of type stdClass as array in [snip]/wp-content/plugins/acf-image-crop-add-on/image_crop-v4.php on line 361

This is on a new install, latest version of WordPress, ACF, and your plugin, no other plugins installed, using Twenty Fourteen theme.

Version 1.1.1 bugs and a small feature change request

Hi @andersthorborg

Thank you for quickly fixing the ACF5 issue for us. Much appreciated.

A few issue that we've spotted...

Force user to crop
Can't really see this doing anything. I can still add an image, and publish the page with out cropping the image. What is meant to happen here? Are we missing something?

Save cropped image to media library = yes & Return = Image object
This actually does not seem to create a new media library item anymore? And this is what is returned as the image object...

stdClass Object
(
    [image] => 2014/07/GSX-RL4_action_1_646x340_acf_cropped.jpg
    [preview] => 2014/07/preview_GSX-RL4_action_1_646x340_acf_cropped.jpg
)

So I'm guessing its a little buggy, but it works still. How ever we need it to work differently.


This is how I think it should work. Please trust me here, it's only a small change...

Use this function: Save cropped image to media library

And rename it to: Save cropped image as new media library item

If is 'NO' get the image path of the target image, use this image path and delete using unlink(image) before the new image is cropped, and then save the new cropped version with exactly the same name. Do not add _acf_cropped into the filename. Basically just replace only the target size image with the new cropped version.

This means, we can use the Image URL, Image ID and Image Object. No need to disable Image ID and Image Object this way :-)

!!! Please note you are using an underscore before the dimensions in your image filename, wordpress uses a hyphen just before the image dimensions rather than a underscore. Line 498.

And this is better because you are updating the original media library item. But you are only ever updating the target size. Which is great because this allows the user to have different cropped sizes for all their images sizes, all in the original media item. In turn allowing us to use the Image Object and Image ID.

If is 'YES' then this should just create a new media library item just for this target image size. Just like it did in version 4. And you can add _acf_cropped into the file name for this version so it does interfere with original media item.


We tried to implement this ourselves. But we didn't test the plugin thoroughly enough before we started modifying the plugin, then released the plugin does not create a new media item anymore, so we were struggling to get the whole thing bug free.

Many Thanks

Image Object Selectable with Save cropped image in media library set to No

So, I'm probably missing something, but the documentation says the only way to use the tool if you've set "Save cropped image in media library" to "No" is via the "Image URL", but "Image Object" is still accessible.

This is fine (in fact, it might be preferred for me), but it appears to still save a cropped image in the media library.

It looks like the only way to reference both the crop and non-cropped versions of an image (which is what I want to do) are if done via the Image Object or possibly via Image ID, or is there a way to do that via Image URL as well?

Ideally I'd like to be able to have only one image saved, and reference the cropped data, as well as the original image. Does that make sense?

Is that possible, and I'm just doing something wrong?

No crop markers visible (ACF 5.4.6 / WP 4.6.1)

This plugin is perfect for my current site, and I was very elated to come across it! Sadly, after install and setting up the field in ACF, the crop modal seems not to function as intended.

The image is shown at full opacity, and when clicking anywhere on the image, it dims as if to show a selection, but no crosshairs or markers show. I've tried it a few times, in a few ways, and inspecting the page / console doesn't help.

Wordpress: 4.6.1
Advanced Custom Fields PRO: 5.4.6
Image Crop Add-on: 1.4.9

Broken with ACF 5.6.1 Update

After updating to ACF 5.6.1 all of my custom fields with cropped images were removed from my site because "Image with Crop" was no longer available as an option in ACF. It defaulted field type to Text instead of Image with Crop.

ACF Pro 5.7-RC1 - Cannot choose image

I am testing the ACF Pro 5.7 release candidate. I find that I can add an "Image with user-crop" field and that it will display in the page edit screen, but when I click the "Add Image" button nothing happens.

I suspect this is related to the major JavaScript changes between ACF Pro versions 5.6 and 5.7.

Still Maintained?

Is this plugin no longer maintained?

If not, are any other good alternatives anyone can suggest?

Thanks!
Scott

Cropping very slow

Running latest version of both plugins ACF PRO 5.5.11 / ACF Image Crop Add-on 1.4.10

Crop still works but is very slow. Upwards of 10 seconds.

[Feature Request] Pass post_id with perform_crop ajax function

Latest version of acf-image-crop (1.4.9) introduce a new filter to customize the postfix of a cropped image.
At this point could be very useful, during the execution of this filter, to know the post_id of the current post where the cropped image is attached.
This way we can strongly customize the name of a cropped image, even based of the current parent post.
This could be easily done passing the post_id variable within the perform_crop function.

Needs polishing in WP 4.8.1 + check compatibility with ACF Pro gallery field

Hey guys,

Noticed some CSS quirks in combination with the latest ACF PRO + WordPress version. See screenshot:

acf-crop-image-field-side

Also, please check on the compatibility with the Gallery field. Adding images to a gallery also triggers the "add" function of a crop field on the same page, inserting the cropped version into the gallery as well.

Keep up the good work.

// T

[Feature Request] do_action after resize images

Hi, it would be possible to add "do_action" before and after resize images (I mean generation of thumbnail, medium,medium_large,large, etc.., not source file!) from source file? It would be usefull to add some watermark to source image for example.

Plugin conflict

When I met this amazing plugin I decided to add it immediately to my boilerplate. However when using this plugin I realized that after cropping ACF-Image-Crop renames files that have already been renamed.

Did I do something wrong? Can you fix it?

Thanks!

Broken with ACF version 5.6.0

Hi there,

With the new update of ACF the plugin doesn't work anymore!

Below are the errors:

Warning: json_decode() expects parameter 1 to be string, array given in /srv/www/perfettivanmelle/htdocs/wp-content/plugins/acf-image-crop-add-on/acf-image-crop-v5.php on line 946

Notice: Undefined index: save_format in /srv/www/perfettivanmelle/htdocs/wp-content/plugins/acf-image-crop-add-on/acf-image-crop-v5.php on line 959

Notice: Undefined index: save_format in /srv/www/perfettivanmelle/htdocs/wp-content/plugins/acf-image-crop-add-on/acf-image-crop-v5.php on line 973

Can you fix this?

Plugin breaks media library

Hi Anders,

I get the two following warnings on one of my websites:

PHP Warning:  Illegal string offset 'hide_cropped' in /data/home/.../wp-content/plugins/acf-image-crop-add-on/acf-image-crop-v5.php on line 640
PHP Notice:  Uninitialized string offset: 0 in /data/home/.../wp-content/plugins/acf-image-crop-add-on/acf-image-crop-v5.php on line 640

I fixed the problem by adding the following code:

$hide = ( isset($options['hide_cropped']) && $options['hide_cropped'] );

The PHP version on the server with the problem is: 5.5.17

Update action broke the whole site

Today I update this plugin and it broke my whole site. Other things were fine but all the images are gone.

I checked the Media page and there are all the images.

I rolled back to version 1.4.11 and it worked again.

I am running WordPress version 4.8.

Different crop and position from different fields

I have a site selling plans. Every plan has 2 featured photos, each of which appear on the site in multiple places at different sizes. I could predefine image crop and position sizes in my custom theme's images.php file, but each image would need a different position which can be very tedious to do by number especially multiple times per image.

Is there a way to create a grouped set of custom fields for each plan, and include conditional visibility for the plan crop sizes. Once the user uploads or selects a featured photo for the plan, the custom crop fields appear to crop and reposition the image for different places.

These should be able to be adjusted/reset later, since they should readily rely on the parent photo.

Issue reference: https://wordpress.org/support/topic/different-crop-and-position-from-different-fields

"Uncaught TypeError: undefined is not a function" when editing Widgets

  • Advanced Custom Fields Pro Version 5.1.7
  • WordPress 4.1
  • Advanced Custom Fields: Image Crop Add-on Version 1.4.1

When I visit Appearance -> Widgets (wp-admin/widgets.php) I'm receiving the following error in my console:

Uncaught TypeError: undefined is not a functioninput.min.js?ver=5.1.7:1
acf.get_selectorinput.min.js?ver=5.1.7:1 acf.get_fieldsinput.js?ver=4.1:435 (anonymous function)input.min.js?ver=5.1.7:1 rinput.min.js?ver=5.1.7:1 tinput.min.js?ver=5.1.7:1 acf.do_actioninput.min.js?ver=5.1.7:1 (anonymous function)load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils,underscore,shortcode,plupload,json2,jq…:2 jload-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils,underscore,shortcode,plupload,json2,jq…:2 k.fireWithload-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils,underscore,shortcode,plupload,json2,jq…:2 m.extend.readyload-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils,underscore,shortcode,plupload,json2,jq…:2 J

screen shot 2015-01-22 at 4 58 15 pm

This error only shows up when the Image Crop Add-on is activated (only ACF and Add-On activated - all other plugins deactivated).

Library: Uploaded to Post vs. All

Built-in Image field includes an option 'Library' allowing selectable images to come from the Media Library or only from images uploaded to the specific post.

Certainly with front-end forms, but also with non-admin post authors, it would be nice to have similar functionality for the image-with-crop field.

Broken in ACF 5.5.5

After updating to 5.5.5, I am no longer able to save image fields with this plug-in.

I have the field loaded on an options page.

I select, and image, crop it, and save the page.

The page reloads without the image, and it is not saved to the database.

Same if I do not crop it.

Using the standard image field works fine.

Two Illegal String Offsets in acf-image-crop-v4.php

This plugin is fantastic, but I've noticed one thing: I get PHP warnings in the error log about illegal string offsets for 'retina_mode' and 'hide_cropped' in acf-image-crop-v4.php. Not a huge deal, to be sure, but I think changing lines 922 and 934 to do an isset() for the appropriate key in $options before setting $value fixes this.

Now, I'm not sure why my install is using v4.php instead of v5, but that's a bit beyond my current understanding. That being said, this whole issue may be moot. But I figured I'd let you know anyway.

Keep up the awesome work!

John

Add image quality option

In the current version of the plugin a quality value of 100 is used when the crop is applied.
$image->set_quality( apply_filters('acf-image-crop/image-quality', 100) );

This unnecessarily blows up the filesize of the generated images and should by default better be set to 90%.

I'd even more appreciate a hook into the plugin to set the compression quality from my functions.php or have an option in the WP-admin's plugin settings.

Add min/max size

It would be great if you could add a feature where you could require the image to be a min/max size.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.