1 # ImageWidgetCrop module
2 Provides an interface for using the features of the [Crop API]. This element
3 provides an UX for using a crop on all fields images or file elements. This
4 module has particularity to purpose capability to crop the same image by “Crop
5 type” configured. It’s very useful for editorial sites or media management
9 - [Requirements](#requirements)
11 - [Known problems](#known-problems)
12 - [Try out the module](#try-out-the-module)
13 - [Installation](#installation)
14 - [Configuration](#configuration)
16 - [Recommended modules](#recommended-modules)
19 * Drupal Module [Crop API].
23 You can follow the evolution of this module [here]
24 (https://www.drupal.org/node/2832789).
28 1. Not compatible with 'Boostrap theme', please switch on 2.x branch to have
29 full support with all themes.
30 2. Support multiple crop variants per URI and crop type, more information
31 [here](https://www.drupal.org/node/2617818).
34 1. Support multiple crop variants per URI and crop type, more information
35 [here](https://www.drupal.org/node/2617818).
38 You can Test ImageWidgetCrop in action directly with the sub-module
39 "ImageWidgetCrop example" to test different use cases of this module.
40 You have two choices to use example module :
43 1. Download and extract project.
44 2. Enable it (`drush en image_widget_crop_examples -y`) or (`admin/modules`)
46 3. Your site frontpage have changed to ImageWidgetCrop Examples welcome page
47 and list all possible examples to try the modules.
49 ### simplytest.me (Online)
50 If you prefer to use SimplyTest.me service, you can test the module online in
53 1. Use one of links [1.x (Stable)] Or [2.x (Stable)].
54 2. Click on the button "Lauch sandbox" and follow common way to install
56 3. Enable ImageWidgetCrop example module on Extend page (`admin/modules`) and
58 4. Enable it (`drush en image_widget_crop_examples -y`) or (`admin/modules`)
60 5. Your site frontpage have changed to ImageWidgetCrop Examples welcome page
61 and list all possible examples to try the modules.
63 [1.x (Stable)]: https://simplytest.me/project/image_widget_crop/8.x-1.5?add[]
64 =media_entity&add[]=media_entity_image&add[]=file_entity&add[]=entity&add[]
65 =token&add[]=inline_entity_form
67 [2.x (Stable)]: https://simplytest.me/project/image_widget_crop/8.x-2.x?add[]
68 =media_entity&add[]=media_entity_image&add[]=file_entity&add[]=entity&add[]
69 =token&add[]=inline_entity_form&add[]=imce&add[]=entity_browser&add[]=ctools
72 1. Download and extract the module to your (`sites/all/modules/contrib`) folder.
73 2. Enable the module on the Drupal Modules page (`admin/modules`) or using
76 The module is currently using Cropper as a library to display, the cropping
78 To properly configure it, do the following:
81 1. Download the latest version of [Cropper].
82 2. Copy the dist folder into:
83 - /libraries/cropper/dist
84 3. Enable the libraries module.
87 1. Set the external URL for the minified version of the library and CSS
88 file, in Image Crop Widget settings (`/admin/config/media/crop-widget`),
89 found at https://cdnjs.com/libraries/cropper.
91 NOTE: The external library is set by default when you enable the module.
95 ImageWidgetCrop can be used in different contexts.
99 * Create a Crop Type (`admin/config/media/crop`)
101 * add Manual crop effect, using your Crop Type, (to apply your crop selection).
102 * Create an Image field.
103 * In its form display, at (`admin/structure/types/manage/page/form-display`):
104 * set the widget for your field to ImageWidgetCrop
105 * at select your crop types in the Crop settings list. You can configure the
106 widget to create different crops on each crop types. For example, if
107 you have an editorial site, you need to display an image on different
108 places. With this option, you can set an optimal crop zone for each of
109 the image styles applied to the image.
110 * Set the display formatter Image and choose your image style, or responsive
112 * Go add an image with your widget and crop your picture, by crop types used
117 * The (`image_crop`) element are already implemented to use, an general
118 configuration of module.
119 * In its ImageWidgetCrop general configuration, at
120 (`admin/config/media/crop-widget`):
121 * open (`GENERAL CONFIGURATION`) fieldset.
122 * at select your crop types in the Crop settings list. You can configure the
123 element to create different crops on each crop types. For example, if
124 you have an editorial site, you need to display an image on different
125 places. With this option, you can set an optimal crop zone for each of
126 the image styles applied to the image
127 * Verify your content using (`image`) field type configured, with
128 (`Editable file`) form widget.
129 * Add an File into content (`node/add/{your-content-type}`) upload your file,
130 click to (`Edit`) button and crop your picture, by crop types used for
135 * Implement (`image_crop`) form element.
136 * Set all variables elements Or use general configuration of module.
138 #### Example of Form API implementation:
140 ##### Common element configuration of ImageWidgetCrop:
142 $crop_config = \Drupal::config('image_widget_crop.settings');
143 $form['image_crop'] = [
144 '#type' => 'image_crop',
145 '#file' => $file_object,
146 '#crop_type_list' => $crop_config->get('settings.crop_list'),
147 '#crop_preview_image_style' => $crop_config->get('settings.crop_preview_
149 '#show_default_crop' => $crop_config->get('settings.show_default_crop'),
150 '#show_crop_area' => $crop_config->get('settings.show_crop_area'),
151 '#warn_mupltiple_usages' => $crop_config->get('settings.warn_
155 ##### Custom element configuration
157 $form['image_crop'] = [
158 '#type' => 'image_crop',
159 '#file' => $file_object,
160 '#crop_type_list' => ['crop_16_9', 'crop_free'],
161 '#crop_preview_image_style' => 'crop_thumbnail',
162 '#show_default_crop' => FALSE,
163 '#show_crop_area' => FALSE,
164 '#warn_mupltiple_usages' => FALSE,
169 You may use ImageWidgetCrop configuration in few contexts and define different
170 options to have desired features by context.
171 If you want to change the global default options you can change it at
172 (`/admin/config/media/crop-widget`) and use configuration
173 `\Drupal::config('image_widget_crop.settings')`.
180 List of all CropTypes configured onto ImageStyle to use and define crop.
182 ### crop_preview_image_style
185 - Default: `crop_thumbnail`
187 Control the sizes of image to crop, you do conserve the aspect ratio of image
188 (Only use Scale in `Width` OR `Height` not both).
190 ### show_default_crop
195 Automatically initialize Crop Area on open `crop` element or file upload if
196 `show_crop_area` option is enable.
203 Automatically open `image_crop` detail elements.
205 ### warn_mupltiple_usages
210 Show a message to prevent users if current crop is used in other places and
211 risk to affect in multiple places in same time.
213 ## Recommended modules
214 All of these modules are supported and tested with Image Widget Crop.
216 * [Crop API]: Provides basic API for images cropping.
217 * [IMCE]: Now supported by all versions of Image Widget Crop. We just have an
218 option to enable of image_crop elements to use it.
219 * [File (Field) Paths]: We support this module and work with Image Widget Crop.
220 * [Bootstrap (theme)]: During lot of efforts to made compatibility with
221 Boostrap all themes are compatible with Image Widget Crop Thank to
222 @markcarver for his precious help.
223 * [Entity Browser]: Fully supported by this module.
224 * [File Entity (fieldable files)]: Fully compatible with this module.
225 * [Automated Crop]: Soon Image Widget Crop use this service to provide a
226 powerful feature request (Automatic crop).
228 [Cropper]: https://github.com/fengyuanchen/cropper
229 [Crop API]: https://github.com/drupal-media/crop
230 [IMCE]: https://www.drupal.org/project/imce
231 [File (Field) Paths]: https://www.drupal.org/project/filefield_paths
232 [Bootstrap (theme)]: https://www.drupal.org/project/bootstrap
233 [Entity Browser]: https://www.drupal.org/project/entity_browser
234 [File Entity (fieldable files)]: https://www.drupal.org/project/file_entity
235 [Automated Crop]: https://www.drupal.org/project/automated_crop