Bug #43624

Gifbuilder cannot generate images

Added by torsten wolter almost 8 years ago. Updated about 3 years ago.

Should have
Image Cropping
Target version:
Start date:
Due date:
% Done:


TYPO3 Version:
PHP Version:
Is Regression:
Sprint Focus:


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.


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'
$bildstring = $this->cObj->IMAGE;

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

Related issues

Related to TYPO3 Core - Bug #46866: wrong image extensions Closed 2013-04-02
Related to TYPO3 Core - Bug #46530: Crop-Scaled images have wrong file content type Closed 2013-03-29 2013-03-29


#1 Updated by Gisèle Wendl almost 8 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) {
            } elseif ($typeimg==2) {
            }elseif ($typeimg==1) {
            }elseif ($typeimg==4) {
            }else  {
                return false;
        } else  {
            return false;
        switch ($ext) {
        case 'gif':
            if (function_exists('imagecreatefromgif')) {
                return imageCreateFromGif($sourceImg);
        case 'png':
            if (function_exists('imagecreatefrompng')) {
                $imageHandle = imageCreateFromPng($sourceImg);
                if ($this->saveAlphaLayer) {
                    imagesavealpha($imageHandle, TRUE);
                return $imageHandle;
        case 'jpg':
            if (function_exists('imagecreatefromjpeg')) {

                return imageCreateFromJpeg($sourceImg);
        case 'jpeg':
            if (function_exists('imagecreatefromjpeg')) {

                return imageCreateFromJpeg($sourceImg);
        // 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

#2 Updated by Tobias Liebig almost 8 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.

#3 Updated by B. Kausch over 7 years ago

  • Target version set to 6.0.5

Should be fixed ASAP.

#4 Updated by Frank Krüger over 7 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

#5 Updated by Chris topher over 7 years ago

  • Subject changed from Problems generating images with gifbuilder in extensions in Typo3 6.0 rc2 to Gifbuilder cannot generate images

#6 Updated by Andreas Keck over 7 years ago

Same Problem with this TypoScript if input image is not png

  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(|);">

#7 Updated by Felix Kopp over 7 years ago

Could you please check if this error can be reproduced with 6.0.5rc1

Thank you!

#8 Updated by B. Kausch over 7 years ago

6.0.5rc1 is functioning for me!

#9 Updated by Christian Kuhn over 7 years ago

  • Status changed from New to Resolved

Solved in young core versions

#10 Updated by Riccardo De Contardi about 3 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF