Bug #43624
closedGifbuilder cannot generate images
0%
Description
Gifbuilder does not render images correctly. This problem happens no matter if Gifbuilder is used from extensions or from TypoScript (for an example with pure TypoScript see note #2).
The problem happens, if the input image has another file type, than the type, which TYPO3 uses internally.
The result are broken output images.
Example:¶
Source im My Extension to create small Image
$imgConfig = array();
$imgConfig['file'] = 'GIFBUILDER';
$imgConfig['file.']['XY'] =$w.','.$h;
$imgConfig['file.']['backColor'] ='#ff0000';
$imgConfig['file.']['transparentColor'] ='#000000';
$imgConfig['file.']['10'] ='IMAGE';
$imgConfig['file.']['10.']['file']= 'fileadmin/somefile.jpg'
$imgConfig['file.']['10.']['file.']['maxW']=$w;
$imgConfig['file.']['10.']['file.']['maxH']=$h;
$bildstring = $this->cObj->IMAGE;
Result:
I get a red(!) Picture.
The image somefile.jpg is rendered in one step into the folder typo3temp/_processed_/csm_somefile_hash.jpg
This file is internal a gif or png (as it is set in the config of typo3)
Later in core/Classes/Imaging/GraphicalFunction.php the imageCreateFromFile function tries to work with the file and uses the fileextension
In my case Extension = jpg and mimetype = png
The function called imagecreatefromjpeg and gets an empty result
Updated by Gisèle Wendl almost 12 years ago
Hi Torsten,
just had the same issue so I made a change to following function imageCreateFromFile
public function imageCreateFromFile($sourceImg) { $imgInf = pathinfo($sourceImg); $ext = strtolower($imgInf['extension']); list($width, $height, $typeimg, $attr) = getimagesize($sourceImg); if (isset($typeimg) && in_array($typeimg, array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_WBMP))) { if ($typeimg==3) { $ext='png'; } elseif ($typeimg==2) { $ext='jpg'; }elseif ($typeimg==1) { $ext='gif'; }elseif ($typeimg==4) { $ext='bmp'; }else { return false; } } else { return false; } switch ($ext) { case 'gif': if (function_exists('imagecreatefromgif')) { return imageCreateFromGif($sourceImg); } break; case 'png': if (function_exists('imagecreatefrompng')) { $imageHandle = imageCreateFromPng($sourceImg); if ($this->saveAlphaLayer) { imagesavealpha($imageHandle, TRUE); } return $imageHandle; } break; case 'jpg': if (function_exists('imagecreatefromjpeg')) { return imageCreateFromJpeg($sourceImg); } break; case 'jpeg': if (function_exists('imagecreatefromjpeg')) { return imageCreateFromJpeg($sourceImg); } break; } // If non of the above: $i = @getimagesize($sourceImg); $im = imagecreatetruecolor($i[0], $i[1]); $Bcolor = ImageColorAllocate($im, 128, 128, 128); ImageFilledRectangle($im, 0, 0, $i[0], $i[1], $Bcolor); return $im; }
This makes it bit more bullet proof for the problem of mixed-up file-extensions
hth
Updated by Tobias Liebig almost 12 years ago
- Category set to Image Cropping
- Complexity set to medium
This does not only happen in extensions, but also in TypoScript:
page.20 = IMAGE page.20.file = GIFBUILDER page.20.file { XY = 100,100 backColor = #ff0000 transparentColor = #000000 10 = IMAGE 10.file = fileadmin/somefile.jpg 10.file.maxW = 100 10.file.maxH = 100 }
The problem is that, while processing the Image (\TYPO3\CMS\Core\Resource\ProcessedFile) it gets cached as file with '.jpg', containing GIF-data, so the file extension should be ".gif" instead.
Gisèles fix looks good (makes imageCreateFromFile not relying on the file extension), but I think this issue must be solved one step before, when processing and caching the file.
Updated by Frank Krüger over 11 years ago
B. Kausch wrote:
Should be fixed ASAP.
This have to be fixed now, this is a massive bug if upgrading existing installations to 6.0.x!
Gisèles fix works!
Cheers Frank
Updated by Chris topher over 11 years ago
- Subject changed from Problems generating images with gifbuilder in extensions in Typo3 6.0 rc2 to Gifbuilder cannot generate images
Updated by Andreas Keck over 11 years ago
Same Problem with this TypoScript if input image is not png
10 = IMG_RESOURCE 10 { file = GIFBUILDER file { XY = 130,230 format = png quality = 100 transparentBackground = 1 10 = IMAGE 10 { file { import.data = page:tx_akstatements_pimage import = uploads/tx_akstatements/ width = 130c height = 230c } #mask = fileadmin/templates/kv/img/maske_anja-bild.png } } stdWrap.wrap = <div id="anja-box" style="background-image:url(|);"> }
Updated by Felix Kopp over 11 years ago
Could you please check if this error can be reproduced with 6.0.5rc1
(http://typo3.org/news/article/release-candidates-of-stable-typo3-cms-branches-available/)
Thank you!
Updated by Christian Kuhn over 11 years ago
- Status changed from New to Resolved
Solved in young core versions
Updated by Riccardo De Contardi about 7 years ago
- Status changed from Resolved to Closed