TYPO3 Romania, Magento, eCommerce, webdesign, content management systems
Snapshot of code changes

Snapshot of code changes

Helping tt_news and jb_gd_resize properly resize article pictures

I've been using jb_gd_resize 1.1.2 and the latest tt_news extension on a server where imagemagick is installed, but the exec rights are disabled, so basically this means no image magick support.

As usual I've installed jb_gd_resize and normal content pictures show up just right, except for the article images in the SINGLE view, which show up at their original size, and thus are not resized.

While looking over the code, I found what the problem was and I also found 2 possible solutions.

In my case, I usually specify just the maxW and/or maxH attribute for each image, in typoscript. For those familiar with it, the code would look like this, for the SINGLE view.

plugin.tt_news.displaySingle.image.file.maxW = 300

This line would be enough for the resizing procedure to work as expected. But with jb_gd_resize it doesn't quite work that way. The problem is the condition on line 48, in class.ux_tslib_gifBuilder.

$wh_noscale = (!$w && !$h) || ($data[0]==$info[0] && $data[1]==$info[1]);

$w and $h take their values from the 2 parameters specified below

plugin.tt_news.displaySingle.image.file.width and
plugin.tt_news.displaySingle.image.file.height
which of course I did not specify, because I use maxW and/or maxH.

Problems and solutions

This way, the $wh_noscale condition always returns true, and my initial image is returned. The easiest way to fix this is just to place one of the 2 lines from above, so you either specify the image.file.width property or the image.file.height property, or both. And you can skip the maxW or maxH property, as the resize is still done keeping the proportions.

The other solution is just to add the following 2 lines before line 48.

    if ($data[0]) $w = $data[0];
    if ($data[1]) $h = $data[1];

This way, the $w and $h are populated with what $this->getImageScale($info,$w,$h,$options); returns, in our case maxW or maxH is also taken into consideration and we get the proper image dimensions, as expected.