365Werk / identitydocuments

A Laravel package for parsing and processing Identity Documents
GNU General Public License v3.0
254 stars 38 forks source link

Unsupported image type. GD driver is only able to decode JPG, PNG, GIF or WebP files. #34

Closed MPJHorner closed 3 years ago

MPJHorner commented 3 years ago

Getting "Unsupported image type. GD driver is only able to decode JPG, PNG, GIF or WebP files."

File was a JPEG.

Intervention\Image\Gd\Decoder::initFromPath vendor/intervention/image/src/Intervention/Image/Gd/Decoder.php:59

Looking at stack trace it can't get the file type because it being given the path. Not the image (it seems). It pulls it from here..

vendor/intervention/image/src/Intervention/Image/AbstractDecoder.php:324

case $this->isSplFileInfo():
return $this->initFromPath($this->data->getRealPath());

Though I wonder if it's on my end, as on "request files" I see this ...

front
{ "pathname": "", "size": false, "mimeType": "undefined" }
back
{ "pathname": "", "size": false, "mimeType": "undefined" }
HergenD commented 3 years ago

I'll look in to the issue once again. I'd like to replicate the error you're getting so could you comment the way you implemented the package and passed the image?

Thanks @MPJHorner

MPJHorner commented 3 years ago

New Laravel install, with basic config and using the simple controller implementation on your example. Passing both front/back image as JPEGs

HergenD commented 3 years ago

I'm able to pass any of the supported image types without issue. Both using images posted in a request and local image path work, and even remote images are supported, so you can give that a go too, for example a simple route to get the MRZ:

Route::post('/id', function(Request $request){
    $id = new IdentityDocument('https://meneercasino.com/sites/default/files/styles/content_width_722_/public/files/kopie_paspoort.jpg');
    $mrz = $id->getMrz();
    return response()->json(['mrz' => $mrz]);
});

returns:

{
    "mrz": "P<NLDDE<BRUIJN<<WILLEKE<LISELOTTE<<<<<<<<<<<SPECI20142NLD6503101F2401151999999990<<<<<82"
}

The error you're getting is not from this package but from Intervention, which means that the issue lies there or in your local environment (most likely). Make sure the GD extension is enabled, and check if there is no limit on the file upload size that might cause your images to not be complete.

HergenD commented 3 years ago

Closing this issue, do feel free to provide me with an update in the comments and I'd be happy to help you out further.

MPJHorner commented 3 years ago

Hey @HergenD used the exact example you gave above. Except I am using tessaract. This is my code...

Controller

$id = new IdentityDocument('https://meneercasino.com/sites/default/files/styles/content_width_722_/public/files/kopie_paspoort.jpg');
        $id->setOcrService(Tesseract::class);
        $mrz = $id->getMrz();

        return response()->json(['mrz' => $mrz]);

Service

class Tesseract implements OCR
{
    public function ocr(Image $image): OcrResponse
    {
        // TODO: Add OCR and return text
        // return new OcrResponse('Response text');
         // Store your image in a temp folder
         $imagePath = sys_get_temp_dir().md5(microtime().random_bytes(5)).'.jpg';
         $image->save($imagePath);

         // Use Tesseract to create text response
         $response = (new TesseractOCR($imagePath))->run();
        // dd($response);
         // Return the new response
         $return = new OcrResponse($response);
         return $return;
    }
}

If i dd($response) in the service I can see the text. However the json restore should $mrz is empty? Does it parse the correct values back from tessaract or do I need to pass it back differently in my service?

It currently returns this..

Werk365\IdentityDocuments\Responses\OcrResponse {#285 ▼
  +text: """
    assront KONINKRIJK DER NEDERLANDEN

    PASSEPOR

    RGDOM OF THE NETHERLANOS, ‘ROAM O65 PAYS-8AS

    P NLD Nederlandse SPECI2014

    De Bruijn

    e/v Molenaar

    saneenengen semtteone

    Willeke Liselotte

    icreterhe osm coeane

    10 MAA/MAR 1965

    1 qe orien one

    Specimen =

    vos ee —

    vir 3 175m

    eens oan annem in peen eon meryrae soe

    15 JAN/JAN 2014 15 JAN/JAN 2024

    A : em ——wewrnaen

    4 Od > Burg. van Stad en Dorp

    Ww. de Pugn
    #00000 —— ®©00000

    P<NLDDE<BRUI JN<<WILLEKE<LISELOTTE<<<<<<<<<<<¢
    SPECI20142NLD6503101F2401151999999990<<<<<82
    """
}
HergenD commented 3 years ago

You seems to get an error due to there being a ¢ in the MRZ part of the tesseract result, I've had similar issues with tesseract being less accurate than google vision, a solution is to filter the result from any characters that you would not need to find on the document, like ¢. You could do that in the tesseract service before returning the result