Typo3 Fluid Image crop of with and height failure

2019-04-15 20:22发布

问题:

Using this code:

<f:image src="/uploads/extkey/{image}" alt="" width="115c" height="70c" />

Produces following HTML output:

<img src="typo3temp/_processed_/csm_testimage_31f6051846.gif" width="115" height="92" alt="">

The image has a wrong height now and there are white bars at top and bottom. I figured out that "92" comes from its proportion (original image is: 1280 × 1024). I guess if the white bars at top and bottom are cut out the height of 70 will be reached. Any ideas why Typo3 is doing that wrong and does some others here having the same problem?

Using Typo3 6.1.5 ImageMagick 6

EDIT #2: Tried different combinations with width,height,crop,maxWidth,maxHeight like:

<f:image src="/uploads/extkey/{image}" alt="" width="115" height="70c" maxHeight="70" />

The results/fails are:

  • Image is not 115x70
  • Image is deformed

回答1:

I have found the correct solution for this Bug. Its now more then 4 years old and still not fixed. The file and the line has changed to: /typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php , Line: 2315

http://forge.typo3.org/issues/19045

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.



回答2:

The c after the dimension means "crop scaling". You cannot crop-scale for both width and height at the same time. So you should maybe set a fixed width (width="115") and then crop-scale the height (height="70c"). This way the image will be resized to width 115 pixel and every pixel that it's higher than 70 pixels will be cropped.

@ggzone: As I already commented, please try doing the same thing with a TypoScript object, meaning: Create an IMAGE cObject with the same parameters and output it on the page. If it doesn't work either, it's a problem of TYPO3 or ImageMagick, if it works, it's a Fluid problem. We need to narrow your problem.



回答3:

You should use maxWidth and maxHeight to specify an box in which the image should be fit

i.e

<f:image src="/uploads/extkey/{image}" alt="" maxWidth="115c" maxHeight="70c" />


回答4:

Params for IM are maxW, maxH not maxHeight, seems they are the same in typo3.
may be this will work:

<f:image src="/uploads/extkey/{image}" alt="" maxH="70c"  maxW="115c" />

Edit:

What is the size of your original image ?

'c' is used for crop and if your original is smaller or in other proportions ...

Try use the 'm' param for Max value ?

<f:image src="/uploads/extkey/{image}" alt="" width="115m" height="70"   />

reference: TYPO3 TS reference