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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

skilip’s picture

Status: Active » Needs review
FileSize
1.28 KB

Here's the patch

bdu’s picture

Status: Needs review » Needs work

These 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.

michaelfavia’s picture

Thank you i was battling scale and resize issues until i found this issue.

elliotttf’s picture

Status: Needs work » Needs review
FileSize
1.17 KB

This patch resets the item's width and height after cropping.

elliotttf’s picture

Ok, 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".

RgnYLDZ’s picture

I'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.

danthewolfe’s picture

#5 worked for me after editing/saving the affected nodes.

BrightBold’s picture

Thanks! Patch in #5 solved my problem (also after editing/saving affected nodes.)

jdanthinne’s picture

Status: Needs review » Reviewed & tested by the community

#5 Solved my problem as well.

joetsuihk’s picture

#5 do not apply to latest dev

joetsuihk’s picture

Status: Reviewed & tested by the community » Fixed

commited, thanks all!

dropfen’s picture

I 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

joetsuihk’s picture

Status: Fixed » Needs review
FileSize
545 bytes

Re #12 Thanks for reporting back!

there is a bug on

+    $lang = isset($entity->{$field_name}[$entity->language]) ? $entity->{$field_name}[$entity->language]: 'und';

$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 ;-)

dropfen’s picture

Thank 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:

isset($entity->{$field_name}[$entity->language]) // In my case it returns false, so I set the key to 'und' 

I hope you understand me, and sorry for my bad english

dropfen

joetsuihk’s picture

$entity->{$field_name}[$entity->language]

will return object, which will be error.

The patch #13 do not work on your machine?

Joe

dropfen’s picture

Oh Yes. My false.

in my patch it should be:

$lang = isset($entity->{$field_name}[$entity->language]) ? $entity->language : 'und';

Of course I need the value not the field array.. Thank you.

dropfen

The patch #13 do not work on your machine?

Sorry, but yes the patch will not work.

dropfen’s picture

New patch attached, and look the Issue number is added to the filename :)

joetsuihk’s picture

Status: Needs review » Closed (fixed)

thx @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

dropfen’s picture

Thx to you, this is my first patch landed into contrib, if it'll :)