Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The Image Field formatter forces the width and height of the image being processed by fetching the dimensions of the original image. This will cause rescaling of the image cropped by Imagefield Crop.
The following patch removes the width and height property in order to maintain the size of the cropped image.
Comments
Comment #1
skilip CreditAttribution: skilip commentedHere's the patch
Comment #2
bdu CreditAttribution: bdu commentedThese are the same symptoms in #1345744: cropped image has incorrect metadata width and height in imagefield. The caching of the width and height is something introduced in core 7.9 with the fix for #1129642: Populate HTML image tags with dimension attributes (like D6 imagefield) without re-introducing I/O. This patch more or less undoes the effect of that fix.
The current behaviour is that image.field module stores the dimensions. It tries to do that with as little i/o as possible. It stores the original dimensions in the form. Because it misses that imagefield_crop has (correctly) changed the image, it uses these original dimensions from the form and not the actual dimensions of the cropped image. We need to fix the core image module.
Comment #3
michaelfavia CreditAttribution: michaelfavia commentedThank you i was battling scale and resize issues until i found this issue.
Comment #4
elliotttf CreditAttribution: elliotttf commentedThis patch resets the item's width and height after cropping.
Comment #5
elliotttf CreditAttribution: elliotttf commentedOk, not sure why I thought that last patch was working but it's not, the function that calls the widget_value function only allows the fid to be changed. Here's another patch that does work but feels a little "heavy handed".
Comment #6
RgnYLDZ CreditAttribution: RgnYLDZ commentedI'm applying the patch manually (Notepad). Found a similar function. Maby from the early patches I applied. Don't know really.
I'm using 7.x-2.x-dev and the last patch works fine for me. Croped image width & height is correct.
Comment #7
danthewolfe CreditAttribution: danthewolfe commented#5 worked for me after editing/saving the affected nodes.
Comment #8
BrightBoldThanks! Patch in #5 solved my problem (also after editing/saving affected nodes.)
Comment #9
jdanthinne CreditAttribution: jdanthinne commented#5 Solved my problem as well.
Comment #10
joetsuihk CreditAttribution: joetsuihk commented#5 do not apply to latest dev
Comment #11
joetsuihk CreditAttribution: joetsuihk commentedcommited, thanks all!
Comment #12
dropfen CreditAttribution: dropfen commentedI found a little bug in the last commit on Line 415, so if $entity->language is defined, and Image Field is 'undefined'. New values will never set.
So here is the Patch. Thx for this Module
dropfen
Comment #13
joetsuihk CreditAttribution: joetsuihk commentedRe #12 Thanks for reporting back!
there is a bug on
$lang
need the key, not the object itself.From the description you had, please try the attached patch for a different approach.
Also, not to being picky, but issue number is suggested to be part of file name, so it will be easier to trace ;-)
Comment #14
dropfen CreditAttribution: dropfen commentedThank you for your reply,
but I think you don't understood my problem.
So, I'll explain it more precise.
In my case the $node/$entity->language is 'de' // German
But the image field don't have an defined language so the key in my image_field is 'und'. And this is why I need to check the field language:
I hope you understand me, and sorry for my bad english
dropfen
Comment #15
joetsuihk CreditAttribution: joetsuihk commentedwill return object, which will be error.
The patch #13 do not work on your machine?
Joe
Comment #16
dropfen CreditAttribution: dropfen commentedOh Yes. My false.
in my patch it should be:
Of course I need the value not the field array.. Thank you.
dropfen
Sorry, but yes the patch will not work.
Comment #17
dropfen CreditAttribution: dropfen commentedNew patch attached, and look the Issue number is added to the filename :)
Comment #18
joetsuihk CreditAttribution: joetsuihk commentedthx @dropfen!
http://drupalcode.org/project/imagefield_crop.git/commit/3e680ca
I will likely prepare a 7.x-1.1-rc1 shortly this week. 1.0 is too broke
Comment #19
dropfen CreditAttribution: dropfen commentedThx to you, this is my first patch landed into contrib, if it'll :)