Image: Encoding format (tmp) is not supported.

Created on 16 Sep 2014  路  11Comments  路  Source: Intervention/image

On windows servers where the file is saved as tmp, file is not recognized as an image. Although, Laravel does validate it as an image with Validator.

Most helpful comment

@olivervogel in my particular scenario I need to save resized files with :100x200 suffixes like file.jpg:100x200. Seems to be impossible in current state of the library, isn't it? Upvoting to add an format parameter. This won't even break the BC. I believe it would be nice to have such such flexibility in library core.

P.S. For anyone looking for a workaround you could use a combination of response() and file_put_contents().

All 11 comments

This happens if you want to save this with the temporary path. I needed to replace the extension.

You have two options.

Use getClientOriginalExtension() to get the original file extension. Or use getimagesize() to get the real image extension. A user can upload an image with a .jpg extension when it is a .png file indeed.

This should work.

$img = Image::make('foo.tmp')

What is not working is, if you're trying to save this file with tmp extension.

// not working if you read .tmp before
$img->save();

// not working
$img->save('foo.tmp');

I tried to keep this simple and determine the output format with the file extension rather than have another parameter for format. Why are you trying to save tmp image files with tmp extension?

It is likely that @marcoflorian is trying to save without an extension - tmp files usually have no extension (e.g. /tmp/r5deku, though I dunno about in Windows). Presumably this is still an issue, though.

If you try to save without extension, the lib tries to determine the format from the mime/type.

The only problematic thing is to save with .tmp extension.

@olivervogel is right. I tried to save with tmp extension.

What I now do is use the function getClientOriginalExtension() and getClientOriginalName().

$img->save('foo' . $img->getClientOriginalExtension());

I think it is fine. I have no tried leaving the extension blank though. As I understand from @olivervogel, this should also work and auto detect the extension.

$img->save('foo');

I think you can form the filename from the UploadedFile object.

$filename = $file->getClientOriginalName() . '.' . $file->getClientOriginalExtension();

But for security reasons I usually don't do this but create random/hashed filenames and convert any format to jpg.

Thanks.

for security reasons I usually don't do this but create random/hashed filenames and convert any format to jpg

@olivervogel Even .gif?

@olivervogel in my particular scenario I need to save resized files with :100x200 suffixes like file.jpg:100x200. Seems to be impossible in current state of the library, isn't it? Upvoting to add an format parameter. This won't even break the BC. I believe it would be nice to have such such flexibility in library core.

P.S. For anyone looking for a workaround you could use a combination of response() and file_put_contents().

vendorintervention\image\src\Intervention\Image\Image.php
I think like this to fix it on windows server error:
row 131:
$file = fopen($path, "rb");
$bin = fread($file, 2); //only read 2 bit
fclose($file);
$strInfo = @unpack("C2chars", $bin);
$typeCode = intval($strInfo['chars1'].$strInfo['chars2']);
$fileType = '';
switch ($typeCode)
{
case 7790:
$fileType = 'exe';
break;
case 7784:
$fileType = 'midi';
break;
case 8297:
$fileType = 'rar';
break;
case 8075:
$fileType = 'zip';
break;
case 255216:
$fileType = 'jpg';
break;
case 7173:
$fileType = 'gif';
break;
case 6677:
$fileType = 'bmp';
break;
case 13780:
$fileType = 'png';
break;
default:
$fileType = 'unknown: '.$typeCode;
}

    if (is_null($path)) {
        throw new Exception\NotWritableException(
            "Can't write to undefined path."
        );
    }

    $data = $this->encode($fileType, $quality);

$img->save('foo' . $img->getClientOriginalExtension());

this worked for me, thanks man

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kamov picture kamov  路  6Comments

ctf0 picture ctf0  路  4Comments

lasithg picture lasithg  路  3Comments

knif3rdev picture knif3rdev  路  6Comments

txusramone picture txusramone  路  6Comments