Project

General

Profile

Actions

Bug #16545

closed

GIFBUILDER indexcolors cropsized images

Added by Sebastian Lenz over 17 years ago. Updated over 13 years ago.

Status:
Closed
Priority:
Should have
Assignee:
Category:
Communication
Target version:
-
Start date:
2006-09-09
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
4.0
PHP Version:
4.3
Tags:
Complexity:
Is Regression:
Sprint Focus:

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

t3lib_stdgraphic.diff (3.24 KB) t3lib_stdgraphic.diff Administrator Admin, 2006-09-15 08:45
class.t3lib_stdgraphic.diff (3.12 KB) class.t3lib_stdgraphic.diff Administrator Admin, 2006-11-02 22:40
class.t3lib_stdgraphic2.diff (3.23 KB) class.t3lib_stdgraphic2.diff Administrator Admin, 2006-11-02 23:10
class.t3lib_stdgraphic3.diff (2.7 KB) class.t3lib_stdgraphic3.diff Administrator Admin, 2006-11-02 23:52
class.t3lib_stdgraphic4.diff (2.34 KB) class.t3lib_stdgraphic4.diff Administrator Admin, 2006-11-15 13:46
crop_scale.diff (2.64 KB) crop_scale.diff Administrator Admin, 2007-02-27 22:02
bug_4186_cropscale_V2.diff (2.33 KB) bug_4186_cropscale_V2.diff Administrator Admin, 2008-02-24 22:12

Related issues 2 (0 open2 closed)

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

Actions
Has duplicate TYPO3 Core - Bug #18435: Cropscaling with GIFBUILDER creates PNG/GIF-File with Extension .jpg (Wrong MIME-Type)Closed2008-03-13

Actions
Actions #1

Updated by Michael Stucki over 17 years ago

Bernhard, could you please have a look at this? Thanks!

Actions #2

Updated by Wolfgang Klinger over 17 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.

Actions #3

Updated by Jo Hasenau over 17 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.

Actions #4

Updated by Jo Hasenau over 17 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.

Actions #5

Updated by Bastian Sauert over 17 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.

Actions #6

Updated by Johannes Vockeroth over 17 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)

Actions #7

Updated by Steffen Kamper about 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 !

Actions #8

Updated by Martin Kutschker about 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.

Actions #9

Updated by Steffen Kamper about 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.'! ';

Actions #10

Updated by Steffen Kamper about 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.

Actions #11

Updated by Franz Koch about 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.

Actions #12

Updated by Bastian Sauert about 17 years ago

The crop_scale.diff patch is fine for me.

Actions #13

Updated by Steffen Kamper about 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).

Actions #14

Updated by Franz Koch about 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?

Actions #15

Updated by Bas van der Togt about 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!

Actions #16

Updated by Franz Koch about 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.

Actions #17

Updated by Steffen Kamper about 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.

Actions #18

Updated by Florian almost 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

Actions #19

Updated by Christopher Hlubek over 16 years ago

+1 For inclusion in CORE!

Actions #20

Updated by Franz Koch over 16 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.

Actions #21

Updated by Helmut Hummel over 16 years ago

I can not reproduce the issue Franz-Xaver Koch mentioned. The patch works perfectly with all my TYPO3 4.1.5 installations...

Actions #22

Updated by Benno Weinzierl about 16 years ago

Works for me too... PLEASE integrate this... At the Moment the croping-functionality cannot be used due to extreme bad quality.

Actions #23

Updated by Helmut Hummel about 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.

Actions #24

Updated by Oliver Hader about 16 years ago

Committed to SVN:
  • TYPO3_4-1 (rev. 3447) --> TYPO3 4.1.7
  • TYPO3_4-2 (rev. 3448)
Actions

Also available in: Atom PDF