Project

General

Profile

Actions

Bug #19045

closed

Cropscale incorrectly crops GIF files

Added by Felix Buenemann over 16 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2008-07-02
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
4.2
PHP Version:
5.2
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

If using cropscale on an imgResource object with a GIF input file whose width is larger than its height eg. 120x80px and cropping to a box eg. 100x100px it will be correctly scaled up to 150x100px and the image area is cropped to 100x100px, but the output file is padded with empty pixels to 150px width, instead of the expected 100px.
PNG and JPG input files are unaffected.

TypoScript/PHP used:
$ts['img'] = 'IMAGE';
$ts['img.']['file'] = $imgFullPath;
$ts['img.']['file.']['format'] = 'jpg';
$ts['img.']['file.']['quality'] = 90;
$ts['img.']['file.']['width'] = '107c'; // This is currently buggy with GIF files (as of T3 4.2.1)
$ts['img.']['file.']['height'] = '107c';

// render thumbnail
$thumbnailImg = $this->cObj->IMAGE;

Typo3 config:
[GFX][gdlib] = 1
[GFX][gdlib_png] = 1
[GFX][im] = 1
[GFX][im_version_5] = im6
[GFX][im_v5effects] = -1
[GFX][im_noScaleUp] = 0
[GFX][png_truecolor] = 1

ImageMagick-6.4.1-8 Macport
PHP 5.2.5 using bundled gdlib (2.0.34 compatible)

Sample attached.
(issue imported from #M8878)


Files

crs_scaling_bug.gif (7.26 KB) crs_scaling_bug.gif Administrator Admin, 2008-07-02 01:37
bug_8878_fix_v1.patch (781 Bytes) bug_8878_fix_v1.patch Administrator Admin, 2010-06-01 15:54
img300x200.gif (1.71 KB) img300x200.gif Administrator Admin, 2010-07-16 15:59
bug_8878_fix_testcase (2.42 KB) bug_8878_fix_testcase Administrator Admin, 2010-07-16 17:21
bug_8878_fix_v1b_svn8197.patch (860 Bytes) bug_8878_fix_v1b_svn8197.patch Administrator Admin, 2010-07-16 17:23
bug_8878_fix_v1b_updated_4_5_19.patch (877 Bytes) bug_8878_fix_v1b_updated_4_5_19.patch Adapted original patch to 4.5.19 Felix Buenemann, 2012-08-21 23:24
19045-original.png (2.62 KB) 19045-original.png Ernesto Baschny, 2013-09-17 20:43
19045-im6-nopatch.png (3.24 KB) 19045-im6-nopatch.png Ernesto Baschny, 2013-09-17 20:43
19045-im6-patched.png (3.17 KB) 19045-im6-patched.png Ernesto Baschny, 2013-09-17 20:43
19045-gm-no-patch.png (3.06 KB) 19045-gm-no-patch.png Ernesto Baschny, 2013-09-17 20:43
19045-gm-patched.png (3.07 KB) 19045-gm-patched.png Ernesto Baschny, 2013-09-17 20:43

Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Bug #18566: Image crop does not work in RC1Closed2008-04-05

Actions
Related to TYPO3 Core - Bug #18986: Cropping gif imagesClosed2008-06-19

Actions
Actions #1

Updated by Johannes Beranek over 15 years ago

t3lib/class.t3lib_stdgraphic.php
line 2181 (in version 4.2.6 that is)

adapt line to
$params .= ' -crop '.$data['origW'].'x'.$data['origH'].'+'.$offsetX.'+'.$offsetY.'! ';

I just added the "!" at the end and it now works - "!" after the crop command tells imagemagick to adjust canvas and viewport.

Didn't test this with any other installations than the one I'm working on right now (4.2.6 with IM 6.3.7), so somebody should probably do this before this fix is commited into core.

Cheers

Actions #2

Updated by Uwe Michelfelder over 15 years ago

I can confirm this.

The fix added here
http://bugs.typo3.org/view.php?id=8025
breaks the correct cropping of GIF-Images in some cases.

Re-adding the ! after the crop command like described above, fixed the problem for me too.

Typo3: 4.2.3
PHP: 5.2.8
ImageMagick: 6.4.4

Actions #3

Updated by Felix Buenemann almost 15 years ago

Hmm, this has been submitted over a year ago, I wonder if it's ever going to get fixed ...

Actions #4

Updated by Wolfgang Klinger almost 15 years ago

That unfortunately doesn't fix it for me using ImageMagick 6.0.7

Actions #5

Updated by Benni Mack over 14 years ago

Felix,

basically your suggestion is a reverse to 8025, do I see this right? Can we narrow the issue down when this happens / or not?

Actions #6

Updated by Felix Buenemann over 14 years ago

This will have to be specialcased for imagemagick version, because the behaviour of im6 is the opposite of im4. Graphicsmagick crops correctly with both syntaxes.

Meaning for im6 we need the ! after -crop dimensions and for 4.2.9 it needs to be ommited.

I did the following tests:

ImageMagick 6.3.7 08/09/09 Q16:
convert -geometry 53x80! -colors 64 -crop 53x53+0+13 old.gif new.gif
Result: 53x80
convert -geometry 53x80! -colors 64 -crop 53x53+0+13! old.gif new.gif
Result: 53x53

ImageMagick 4.2.9 99/09/01:
convert -geometry 53x80! -colors 64 -crop 53x53+0+13 old.gif new.gif
Result: 53x53
convert -geometry 53x80! -colors 64 -crop 53x53+0+13! old.gif new.gif
Result: 53x80

GraphicsMagick 1.1.11 2008-02-23 Q8:
convert -geometry 53x80! -colors 64 -crop 53x53+0+13 old.gif new.gif
Result: 53x53
convert -geometry 53x80! -colors 64 -crop 53x53+0+13! old.gif new.gif
Result: 53x53

Actions #7

Updated by Felix Buenemann over 14 years ago

The attached patch bug_8878_fix_v1.patch against 4.3.3 should fix the issue for both im6 and im4 by making the behaviour dependant on the im version.

(im4 uses #18566 behaviour, while im6/gm uses pre #18566 behaviour)

Actions #8

Updated by Felix Buenemann over 14 years ago

Little reminder, please review Benjamin.

I'm currently using this patch on 4.2.12, 4.3.3 and 4.4.0 installations without problems.

Actions #9

Updated by Chris topher over 14 years ago

Hi Felix,

the normal workflow is that who wrote a patch send it as an RFC to Core List.
There it will get attentnion (other than here).
Check what you should do: http://typo3.org/teams/core/core-mailinglist-rules

Actions #10

Updated by Felix Buenemann over 14 years ago

Simple testcase:

temp.img = IMAGE
temp.img {
file = fileadmin/test/img300x200.gif
file.width = 147c
file.height = 147c
wrap = <div style="background:#aaa;float:left">|</div><div style="clear:both" />
}

page = PAGE
page {
5 < temp.img
}

I'll attach img300x200.gif, which is a squared gray box on a 300x200 transparent background.

Actions #11

Updated by Felix Buenemann over 14 years ago

Attached testcase visualization "bug_8878_fix_testcase", please rename to .png, sorrry.

Attached clean patch against svn rev 8197.

Actions #12

Updated by Felix Buenemann over 14 years ago

Submitted for review.

Actions #13

Updated by Stefan Galinski almost 13 years ago

  • Target version deleted (0)

Hi Felix,

Can you please resubmit your patch if this is still valid?
http://wiki.typo3.org/Contribution_Walkthrough_Tutorials.

Actions #14

Updated by Anonymous over 12 years ago

This problem seems to be still existent in T3 4.5.19

A GIF picture original of 150px wide by 80px high cropscaled to 80px by 80px results in the 'image' being cropped, but the file has a transparent padding of 35px left and 35px right, resulting in an image of, you guessed it, 150px wide and 80px high.

I've tested using im6 and gm. Both have the same result.

Actions #15

Updated by Michael Stucki over 12 years ago

Hi Matthias,

similar to Stefan, I'd like to invite you to try to submit a patch for this bug. As it seems, someone has attempted to create a patch already, however it is old and might need to be updated.

If you need further help, let me know.

- michael

Actions #16

Updated by Felix Buenemann over 12 years ago

Adapted patch to 4.5.19 (only whitespace changes, untested!).

Actions #17

Updated by Felix Buenemann over 12 years ago

@Matthias: Try the updated patch on 4.5.19. I haven't tested it due to lack of time, but it should work.

Actions #18

Updated by Simon Schaufelberger over 12 years ago

Hi Felix, please make a patch with git and push it to gerrit.

Actions #20

Updated by Gerrit Code Review over 12 years ago

  • Status changed from Needs Feedback to Under Review

Patch set 2 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/13996

Actions #21

Updated by Anonymous over 12 years ago

@Felix I will try to test it this week. Thanks for the quick reply! :)

Obviously I will report back when i've tested the patch.

Actions #22

Updated by Gerrit Code Review about 12 years ago

Patch set 1 for branch TYPO3_4-5 has been pushed to the review server.
It is available at http://review.typo3.org/14132

Actions #23

Updated by Gerrit Code Review over 11 years ago

Patch set 4 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/13996

Actions #24

Updated by Gerrit Code Review about 11 years ago

Patch set 5 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/13996

Actions #25

Updated by Gerrit Code Review about 11 years ago

Patch set 6 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/13996

Actions #26

Updated by Gerrit Code Review about 11 years ago

Patch set 7 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/13996

Actions #27

Updated by Gerrit Code Review about 11 years ago

Patch set 1 for branch TYPO3_6-1 has been pushed to the review server.
It is available at https://review.typo3.org/23872

Actions #28

Updated by Gerrit Code Review about 11 years ago

Patch set 1 for branch TYPO3_6-0 has been pushed to the review server.
It is available at https://review.typo3.org/23873

Actions #29

Updated by Stefan Neufeind about 11 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

Updated by Ernesto Baschny about 11 years ago

I was trying to understand the issue and thus testing the patch under TYPO3 4.5 (https://review.typo3.org/#/c/14132/) and the proposed example:

file = fileadmin/test/img300x200.gif
file.width = 147c
file.height = 147c

The original 300x200 image looks like this (darker gray is the transparent area):

This is the crop-scaled with IM6 (6.7.7 Debian Wheezy) and no 4.5 patch applied:

This is the crop-scaled with IM6 (6.7.7 Debian Wheezy) and the mentioned patch applied:

Strange enough, in GM (1.3.16 Debian Wheezy) the unpatched state result in:

With no change in the patched version:

Actions #31

Updated by Ernesto Baschny about 11 years ago

While the GM situation is unchanged (and seems buggy in any case), the IM6 situation seems to be fixed. I have no IM5 "at hand" but trust that it works like mentioned. From the IM documentation:

From ImageMagick version 6.2.4-5, you can add a new special flag to the "-crop" argument. This flag '!' will tell crop to adjust the canvas/page information of the returned image so that it is relative to the area cropped.

NICE! Adding features in a minor-patchlevel release. :)

Actions #32

Updated by Ernesto Baschny about 11 years ago

BTW huge explanation on the -crop usage here: http://www.imagemagick.org/Usage/crop/

Actions #33

Updated by Max Roesch about 11 years ago

I can confirm the IM patch works with TYPO3 6.1.5 and IM Version 6.8.7-0

Actions #34

Updated by Jonas Eberle over 10 years ago

I applied this patch to 4.7.18 by changing ./t3lib/class.t3lib_stdgraphic.php line 2228 and it fixes the .gif-crop-problem there, too.
Any chance of getting this applied to the 4.7-branch upstream?

Greets,
Jonas

Actions #35

Updated by Benni Mack about 6 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF