Bug #19045
closedCropscale incorrectly crops GIF files
100%
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
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
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
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 ...
Updated by Wolfgang Klinger almost 15 years ago
That unfortunately doesn't fix it for me using ImageMagick 6.0.7
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?
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
Updated by Felix Buenemann over 14 years ago
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.
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
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.
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.
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.
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.
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
Updated by Felix Buenemann over 12 years ago
Adapted patch to 4.5.19 (only whitespace changes, untested!).
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.
Updated by Simon Schaufelberger over 12 years ago
Hi Felix, please make a patch with git and push it to gerrit.
Updated by Felix Buenemann over 12 years ago
@Simon: done: http://review.typo3.org/13996
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
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.
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
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
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
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
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
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
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
Updated by Stefan Neufeind about 11 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 2bb534890d1cee98add4d738c7e5587b62ec06a6.
Updated by Ernesto Baschny about 11 years ago
- File 19045-original.png 19045-original.png added
- File 19045-im6-nopatch.png 19045-im6-nopatch.png added
- File 19045-im6-patched.png 19045-im6-patched.png added
- File 19045-gm-no-patch.png 19045-gm-no-patch.png added
- File 19045-gm-patched.png 19045-gm-patched.png added
- Assignee deleted (
Benni Mack) - Is Regression set to No
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:
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. :)
Updated by Ernesto Baschny about 11 years ago
BTW huge explanation on the -crop usage here: http://www.imagemagick.org/Usage/crop/
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
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