Using 'manual crop' style, and leaving the either or both of the minimum height or minimum width fields blank results in missing height attributes on the resulting image tag.
I believe the problem is due to the fact that the image_resize_dimensions
callback is being used as the dimensions callback to process this style (manualcrop_crop), and that callback expects to have both width and height set. The issue can be partially resolved by switching to use the image_scale_dimensions
callback instead which will generate correct dimensions if either one or the other is set. However this raises an undefined index warning as the 'upscale' attribute is not set. Also, this doesn't work correctly if neither of the minimum dimensions are specified.
It seems that the 'Manual crop' style is really a mixture of 'manual scale' and 'manual crop' functionality. Either, what we need is to split crop and scale actions into two separate actions ('manual crop' and 'manual scale'), which both more closely mimic cores 'scale' and 'crop' actions in which case we could continue to use core's dimension callbacks. Or alternatively, we need our own dimensions callback that handles this action more cleverly.
Comment | File | Size | Author |
---|---|---|---|
#30 | interdiff-28-30.txt | 2.42 KB | ShaunDychko |
#30 | manualcrop-add-image-dimension-attributes-1556244-30.patch | 5.21 KB | ShaunDychko |
#28 | interdiff-24-28.txt | 1.68 KB | BarisW |
#28 | manualcrop-using_manual_crop-1556244-28.patch | 5.66 KB | BarisW |
#24 | manualcrop-using_manual_crop-1556244-24.patch | 5.62 KB | Fabianx |
Comments
Comment #1
mrfelton CreditAttribution: mrfelton commentedOn further investigation, it seems impossible to do this without fixing core. See #1364670: ImageStyle::transformDimensions unable to deal with all effects.
Comment #2
mrfelton CreditAttribution: mrfelton commentedWith patch from http://drupal.org/node/1364670#comment-5943622 applied to drupal core, this patch fixes the issue by defining our own dimensions callback that is able to properly calculate the new dimensions.
Comment #3
MatthijsThanks four your patch, I'll commit it as soon as you're other patch makes it to the core.
Comment #4
mrfelton CreditAttribution: mrfelton commentedAwesome. Maybe you could review and provide some feedback on that core issue to help speed it along?
Comment #5
MatthijsNo problem, but do I have to review both the 7.x and 8.x patch (because this is a Drupal 8.x issue)?
I'm not an experienced core contributor :-)
Comment #6
Wolfgang Reszel CreditAttribution: Wolfgang Reszel commentedThanks, the patch works well for D7.
Edit:
Sorry, i disabled error messages. The following warning will be shown:Sorry, i forgot to patch the core, but $data['path'] is always NULL. It works anyway. ;-)
Comment #7
mrfelton CreditAttribution: mrfelton commentedI'm having some issues with this now, sometime resulting in images with a 0 width and no height attributess.
Comment #8
Wolfgang Reszel CreditAttribution: Wolfgang Reszel commentedThe patch is not correct. Replace ...
... with ...
Comment #9
mrfelton CreditAttribution: mrfelton commentedThanks! Updated patch
Comment #10
Wolfgang Reszel CreditAttribution: Wolfgang Reszel commentedThe Patch does not work with the latest Dev version.
Comment #11
Ankabout CreditAttribution: Ankabout commentedPatch works for me on 7.x-1.3, but then I get the following error on all pages with a cropped image:
Notice: Undefined index: path in manualcrop_resize_dimensions() (line 960 of /var/www/vhosts/*******/httpdocs/sites/all/modules/manual-crop/manualcrop.module).
Comment #12
Ankabout CreditAttribution: Ankabout commentedJust figured that this is quite a major bug since it simply causes images not to load on ALL IE browsers.
Comment #13
Ankabout CreditAttribution: Ankabout commentedSetting the following properties in CSS fixes the problem in the mean time:
Comment #14
mrfelton CreditAttribution: mrfelton commentedUpdated patch to apply against latest dev.
Comment #15
Jon_B CreditAttribution: Jon_B commentedI don't think the patch is quite right. In some uses, i.e. depending on what other image effects are applied to the image style, it will appear correct. However, the issue with the
$data['path'] = NULL
, as raised in other issues / previous comments, means that the width and height of the manual crop cannot be queried in themanualcrop
table in the database.The issue is that the core image module is not set up to pass the path of the image to the effect callback. This probably could be patched, but the signature of the callback function would need to be changed, so that the path could be passed to the function. This would cause problems for all modules that implement a 'dimensions callback' function. So not sure how to resolve this issue for this patch.
One way may be to use
hook_theme_registry_alter
to change thetheme_image_style
callback, so that a new callback function could be created to work out the correct width/height attributes.Comment #16
OnkelTem CreditAttribution: OnkelTem commentedThis is updated version of the patch against the latest dev (6 Mar 2012).
It adds 3 different dimension callbacks for crop, crop and scale, and for reuse effects. The latter callback simply calls
image_style_transform_dimensions()
recursively. Please test & review.NOTE: This patch requires applying core patch from #1364670-9: ImageStyle::transformDimensions unable to deal with all effects.
Comment #17
OnkelTem CreditAttribution: OnkelTem commentedPatch from #16, against the latest dev.
See the NOTE from #16.
Comment #18
MatthijsComment #19
mrfelton CreditAttribution: mrfelton commentedUpdated patch to apply cleanly against latest dev with git apply (patch from #17 applied with fuzz)
Comment #19.0
mrfelton CreditAttribution: mrfelton commentedfix typo
Comment #20
bessone CreditAttribution: bessone commentedany update on this issue?
Comment #21
xkhaven CreditAttribution: xkhaven commentedIf someone is still looking for a quick fix for empty IMG tag dimension attributes, here's my solution.
Comment #22
OnkelTem CreditAttribution: OnkelTem commentedUpdated patch which also covers "Auto reuse" feature.
Please test & review
p.s. oops, I created patch with my credentials in autopilot. You are free to not use this data. Sorry.
Comment #23
Fabianx CreditAttribution: Fabianx commentedRe-rolled patch for 7.x-1.4+109-dev.
One change in crop style was changed.
Comment #24
Fabianx CreditAttribution: Fabianx commentedAnd add some more doxygen and fix code style.
Comment #25
OnkelTem CreditAttribution: OnkelTem commentedLet's commit it!
Comment #26
rbomhof CreditAttribution: rbomhof commentedJust applied this patch, as we needed it to get the "img with srcset" functionality from the picture module: https://www.drupal.org/node/2450863#comment-10116088. Do you think this will be committed soon? Also we see an error with one of our image styles that has a "Manual Crop: Reuse cropped style" effect:
Notice: Undefined index: path in manualcrop_reuse_transform_dimensions() (line 1037 of manualcrop.module).
Not sure if anyone else has come across that.
Comment #27
Fabianx CreditAttribution: Fabianx at Tag1 Consulting commented#26: This needs a core patch for D7 (and D8).
Comment #28
BarisW CreditAttribution: BarisW at LimoenGroen commentedThanks for the patch. It works perfect. I've attached a re-roll of #24 against 7.x-1.x with some minor Drupal coding standard improvements.
Would be nice to have this committed, since having width and height attributes on images really improves the end user experience (since the browser can allocate the space even before the image is downloaded).
Comment #29
AndyThornton CreditAttribution: AndyThornton commentedthanks BarisW and all
we'd love to see this patch applied too.
each time i apply it, though ... i have to modify a couple of lines to stop it erroring
1018: $crop = manualcrop_load_crop_selection(isset($data['path']) ? $data['path'] : null, $data["style_name"]);
and
1039: image_style_transform_dimensions($data['reuse_crop_style'], $dimensions, isset($data['path']) ? $data['path'] : null);
i guess this must be some idiosyncrasy of our system ... as no one else seems to mention it.
Comment #30
ShaunDychko CreditAttribution: ShaunDychko for Bellin commentedThe
manualcrop_crop_and_scale_transform_dimensions
dimensions callback is invoked by image_style_transform_dimensions which passes only the style name and the original dimensions of the image. This means the$data['path']
will always be an undefined index, andmanualcrop_load_crop_selection($data['path'], $data["style_name"]);
will always return false. This meansmanualcrop_crop_and_scale_transform_dimensions
can only ever return the dimensions configured in the style settings, so I've simplified the code for that function and removed the "Undefined index" error message it was causing. This creates the known limitation, which I think belongs in another issue since solving it requires changing something in Drupal core to makeimage_style_transform_dimensions
pass along the image path:The image_style_transform_dimensions takes only two parameters, so I removed the third on a few lines.
Comment #31
ShaunDychko CreditAttribution: ShaunDychko for Bellin commentedComment #32
BarisW CreditAttribution: BarisW at LimoenGroen for Historisch Centrum Overijssel commentedTested the patch in #30. The width and height tags appear, and I see no notices. Great work!
Comment #33
Chris CharltonWow. Long time coming. :)
Comment #34
BarisW CreditAttribution: BarisW at LimoenGroen for Historisch Centrum Overijssel commentedPing
Comment #35
Chris CharltonPing+
Comment #36
vinmassaro CreditAttribution: vinmassaro commentedI have 'Manual Crop: Automatically reuse cropped style' set for my image style, with a fallback style that uses 'Scale and Crop' to 575x334. I offer 3 'Manual Crop: Crop and Scale' presets at 3 different sizes. What I'm finding is that with this patch, the correctly sized image is loaded into the page, but the height/width attributes are always set to the fallback image style dimensions. In the code, it looks like
manualcrop_auto_reuse_transform_dimensions()
never gets a style from_manualcrop_get_auto_reuse_style_name()
and always uses the fallback image dimensions.Nobody has mentioned having a fallback image style set, so I'm setting status back to 'Needs work'. If there is a misconfiguration on my end, please let me know. Thanks!