php-imagine / Imagine

PHP Object Oriented image manipulation library
https://imagine.readthedocs.io
Other
4.42k stars 530 forks source link

Jfif extension not handled #726

Closed ghost closed 2 years ago

ghost commented 4 years ago

Issue description

Imagine won't save a jpeg file with jfif extension although the library is able to crop the file.

What version of Imagine are you using?

1.2.1

What's the PHP version you are using?

7.2.17-1

What's the imaging library you are using [gd/imagick/gmagick/any]?

gd

What's the imaging library configuration

GD Support => enabled GD headers Version => 2.2.5 GD library Version => 2.2.5

Minimal PHP code to reproduce the error:

Example file : imagetest.tar.gz (it's tar gz as github doesn't accept jfif images)


$stream = fopen($filename, 'r');
$imagine = new Imagine\Gd\Imagine();
$image = $imagine->read($stream);
$manipulator = $image->copy();
$box = new Box(300,300);
$manipulator = $manipulator->thumbnail($box);
$manipulator->save(__DIR__ . '/altered-' . basename($filename));

Proposed solution

Replace \Imagine\Gd\Image::normalizeFormat() by

    private function normalizeFormat($format)
    {
        $format = strtolower($format);

        if ('jpg' === $format || 'pjpeg' === $format || 'jfif' === $format) {
            $format = 'jpeg';
        }

        return $format;
    }
mlocati commented 4 years ago

@sylvain-msl-talkspirit what about submitting a pull request?

mlocati commented 2 years ago

Fixed by #727