Bug #16545
closedGIFBUILDER indexcolors cropsized images
0%
Description
Giving the gifbuidler the command to cropsize an image makes him convert the image to a gif, even if both source and destination are truecolored images like jpg. The following directive leads to an ugly result, at least in the typo3-version 4.0 im currently running on:
temp.test = IMAGE
temp.test.file {
file = fileadmin/debug/teaser.jpg
file.width = 550c
file.height = 150c
}
As this is a “simple” image-action, the directive is delegated to imageMagickConvert() in class.t3lib_stdgraphic.php. There is a special handling for cropsized images useing, after scaleing the image, a gifbuilder-object in order to create an offest for the the final result. Somewhere along the way, this gifbuilder creates a gif-file out of jpeg files. I simply replaced the gifbuilder-call by another imagemagick-call, working pretty fine for me:
if ($data['crs']) {
if ($this->dontCheckForExistingTempFile || !$this->file_exists_typo3temp_file($output, $imagefile)) {
$crsOutput = str_replace('pics/', 'pics/crs-', $output);
$this->imageMagickExec($imagefile.$frame, $output, $command);
if (!$data['origW']) $data['origW'] = $data[0];
if (!$data['origH']) $data['origH'] = $data[1];
$ofX = intval(($info[0] - $data['origW']) / 2 * (($data['cropH'] + 100) / 200));
$ofY = intval(($info[1] - $data['origH']) / 2 * (($data['cropV'] + 100) / 200));
$command = '-crop ' . $data['origW'] . 'x' . $data['origH'] . '+' . $ofX . '+' . $ofY;
$this->imageMagickExec($output, $output, $command);
(issue imported from #M4186)
Files
Updated by Michael Stucki about 18 years ago
Bernhard, could you please have a look at this? Thanks!
Updated by Wolfgang Klinger about 18 years ago
The attached patch works (the original code had typos),
though I think this depends on the ImageMagick version and use of GD or something like that (no time to take a look at it further) and should at all events be revised before adding it to the Core.
Updated by Jo Hasenau about 18 years ago
This wont work, since the offset that is used to move the cropping area around the image is not taken into consideration.
It will take at least two different crop actions and a bit more calculation with the percentages after the "c" suffix to get the same cropping results as with the original GIFBUILDER setup but with 24bit colordepth.
Working patch attached ...
To make the m.mask feature work with cropscaled images too, I created a new diff.
It sets a new $data Array based on the size of the cropscaled image.
Updated by Jo Hasenau about 18 years ago
Sorry - I have to admit that I misunderstood how the crop command works. So the first approach seems to be the best solution.
Anyway we would need the newly crated $data Array after the operation so that the m.mask feature will get the correct size of the image.
Will add a new patch.
Updated by Bastian Sauert about 18 years ago
As far as I can see, it is not necessary to call imagemagick twice. With my patch (class.t3lib_stdgraphic4.diff) "resizing" and cropping is performed with one command, which saves time and should lead to a better quality (by reducing the number of jpeg de-/encoding steps).
Furthermore the original patch introduces a factor 1/2 in the calculation of the crop offset, which leads to a different image detail than the original implementation. I don't know whether this was intended.
Finally, the $data array is not used after the imagemagick-call as far as I can see. Therefore I don't see any need to update it. It might be useful to update the $info array (or at least $info0 and $info1). However, the original implementation didn't do that either.
Updated by Johannes Vockeroth almost 18 years ago
The patch4 worked for me! Thank you so far!
Btw. I came to this issue, because I do not have GDLib installed and wondered why cropping needs GDLib (or simply produced a white screen with no error message)
Updated by Steffen Kamper over 17 years ago
I tested patch4 in RC1 and it works perfect !
Why is'nt it integrated since now ? This Bugpost is quite old ...
Please integrate it, without cropscale makes no sense !
Updated by Martin Kutschker over 17 years ago
Bastian, the info array is update near the end of the function if $params is set. So instead of changing $command, the patch should modify $params, to force the update.
Updated by Steffen Kamper over 17 years ago
Hi Martin,
the $command is added with $param. Before it was
$command = $this->scalecmd.' '.$info0.'x'.$info1.'! '.$params.' ';
Bastian changed the $command and added it afterwords.
Do you mean to add the modification at the and like that ?
$command.=$params.' '.$tmpParams;
ah - i think i see what you mean:
if ($params) { ...
to update the info. For this case only this has to be changed:
$params.= ' -crop '.$data['origW'].'x'.$data['origH'].'+'.$ofX.'+'.$ofY.'! ';
Updated by Steffen Kamper over 17 years ago
i made the changes Martin mentioned and tested, it works for me.
It's in crop_scale.diff
Please can you check this.
Updated by Franz Koch over 17 years ago
have you tried to cropscale GIF images? I get very strange results in 4.1RC2. With JPG images everything works like expected. Very strange.
edit:
After applying the last patch 'crop_scale.diff' everything worked fine.
Updated by Bastian Sauert over 17 years ago
The crop_scale.diff patch is fine for me.
Updated by Steffen Kamper over 17 years ago
can this fix go to svn ?
Today i had this problem on a server, that the cropscaled were gif and created with wrong filecreatemask, applying this patch helped and everything worked as it should (jpg and right filecreatemask).
Updated by Franz Koch over 17 years ago
Lately I had again a problem with cropscaling GIF images, even with the applied patch that worked allready on the same server. I used graphicsmagic and the results where very strange. The image dimension where correct, but the offset of the image inside the cropping-canvas was wrong. After switching to ImageMagick5.x the problem was gone. Very strange though. I tried to debug this but couldn't find any bug. The parameters given to the IM/GM-command seemed to be correct (as far as I can say) - and it worked by only switching to IM, so it might be a GM bug?
Updated by Bas van der Togt over 17 years ago
Dummy question... sorry
How can i install the "class.t3lib_stdgraphic4.diff" file in SSH,
which command do i have to use?
Thank you!
Updated by Franz Koch over 17 years ago
Addition to my note from 04.04.2007:
The cropscaling finally worked again after I defined the resulting image-type to be always "jpg", so the problem appears only when the source and resulting image are gif. And as mentioned it also appears WITH the applied patch 'crop_scale.diff'.
Hope that helps debugging somehow as I haven't been successful on debugging myself.
Updated by Steffen Kamper over 17 years ago
@Bas - patch should be your friend (http://www.die.net/doc/linux/man/man1/patch.1.html)
@Franz Koch - yes, gif is problematic. I also see a bad quality with gif files, I'm not sure if this is a side effect or still exists before.
Updated by Florian over 17 years ago
Would it be possible to include the patches into the CORE files? I guess this is a very useful function, especially if you want to have a lot of control over your images. And for non developers it's not that easy to add the DIFFs through
GNU-Tools even it's not impossible ;-)
thanks indeed
Updated by Franz Koch about 17 years ago
hey guys - will it make it into 4.2? It'll be very nice, because currently the image quality is crap.
I just tried to apply the patch on 4.1.3 - but I get some errors there. It seems to write jpg-data into a file with gif file extension and then tries to use the image as gif which of course fails. Haven't found a solution so far.
Updated by Helmut Hummel almost 17 years ago
I can not reproduce the issue Franz-Xaver Koch mentioned. The patch works perfectly with all my TYPO3 4.1.5 installations...
Updated by Benno Weinzierl over 16 years ago
Works for me too... PLEASE integrate this... At the Moment the croping-functionality cannot be used due to extreme bad quality.
Updated by Helmut Hummel over 16 years ago
Added current path aginst 4_2 branch
@Benno:
This issue is pending in core list to be integrated at least in TYPO3 4.2.
I don't know if this will also go into 4.1.x, as it may be considered as a feature rather than a bugfix.
Updated by Oliver Hader over 16 years ago
- TYPO3_4-1 (rev. 3447) --> TYPO3 4.1.7
- TYPO3_4-2 (rev. 3448)