Bug #43624

Gifbuilder cannot generate images

Added by torsten wolter almost 7 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Image Cropping
Target version:
Start date:
2012-12-05
Due date:
% Done:

0%

TYPO3 Version:
6.0
PHP Version:
5.3
Tags:
Complexity:
medium
Is Regression:
Sprint Focus:

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


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

History

#1 Updated by Gisèle Wendl almost 7 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

#2 Updated by Tobias Liebig almost 7 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 6 years ago

  • Target version set to 6.0.5

Should be fixed ASAP.

#4 Updated by Frank Krüger over 6 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 6 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 6 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(|);">
  }

#7 Updated by Felix Kopp over 6 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!

#8 Updated by B. Kausch over 6 years ago

6.0.5rc1 is functioning for me!

#9 Updated by Christian Kuhn over 6 years ago

  • Status changed from New to Resolved

Solved in young core versions

#10 Updated by Riccardo De Contardi almost 2 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF