Search code examples
phpbase64pngtcpdf

Does TCPDF have limits on base64 images?


I'm upgrading an installation of TCPDF from version 4.9 to version 6.4.2 and noticed an odd behaviour with base64 images.

The example image from https://tcpdf.org/examples/example_009/ correctly loads the base64 "PHP Rules" image, but I can't get any other valid base64 image to show. Instead I am seeing a blank PDF page with no image.

I've scaled down example 009 from the TCPDF docs to isolate the issue:

This loads the "PHP Rules" image

require_once('tcpdf_include.php');
$pdf = new TCPDF();
$pdf->AddPage();
$img_encoded = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABlBMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDrEX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';
$imgdata = base64_decode($img_encoded);
$pdf->Image('@'.$imgdata);
$pdf->Output('example_009.pdf', 'I');

This generates a blank PDF page instead of adding a curly drawing:

require_once('tcpdf_include.php');
$pdf = new TCPDF();
$pdf->AddPage();
$img_encoded ='iVBORw0KGgoAAAANSUhEUgAAAZAAAACWCAYAAADwkd5lAAAI2UlEQVR4nO3dMW8cxxUAYP0E/gT9AJv7JN/OrIAAYm0EIEt3YhGktVwGCGB2MZDCRKp0ZpO0YpMmhaUfYEAsXKQJKATpUpCAgTg2nFyKveXt3h1pUhI5e7zvAxYiyDvqiRT27cy8N/PgAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABsvDrqePKofvrkUf20ieZh6XgAGIkmmodNTHZy5N0m0uc50osm8ssc6ayJPL3ietm+Pu9KLABrLCK2hqOF9CxH/rSJ9Hl35UgvZtdxE/n0ZxLEtIk8zZHOm0ivcqST9uPl16Qq/SdHOstRf5kj70bEVumfBwCXqKOONjHkl9dJBIOkUKV/dMmhTQz5uIl0lCM/b6Leb2Kyc1US6EYtTaSDHPk4VenvKxLPixx59y5/JgBcop1qq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ZLu5ju2tA9Wlb5fnLayaA6M0uJUSel4NtGK42t/ti8EoDgJpLyI2FrcD8t5H8DoLSYQc+1lRMRWrtK3uUrTHPW/JQ9g9Ja30jDfDsA1XHcvJgAYWN4m4/LDjADgwk3OowCAgYUSUueiA3A9OdLJdY9UBYALuUpfD0Yh25NPSscEwBpI1eSP/S3FrzpWFQAuLJfy5tPSMQGwBpYrsfK0ifxV6bgAWAOLC+lN5Gmq6i9KxwXAyDUx2Vnc0C9HmuZIZznSiyeP6qelYwRgpPpd6cMtxS92h7W4DsBqjz94vN1EfbRqSitHPi4dHwBrIiK22iNW04EGQwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4DL/B7EdVIEgTgUAAAAAAElFTkSuQmCC';
$imgdata = base64_decode($img_encoded);
$pdf->Image('@'.$imgdata);
$pdf->Output('example_009.pdf', 'I');

I've validated the base64 code (https://base64.guru/converter/decode/image) and the full base64 image loads correctly in a browser: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAACWCAYAAADwkd5lAAAI2UlEQVR4nO3dMW8cxxUAYP0E/gT9AJv7JN/OrIAAYm0EIEt3YhGktVwGCGB2MZDCRKp0ZpO0YpMmhaUfYEAsXKQJKATpUpCAgTg2nFyKveXt3h1pUhI5e7zvAxYiyDvqiRT27cy8N/PgAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABsvDrqePKofvrkUf20ieZh6XgAGIkmmodNTHZy5N0m0uc50osm8ssc6ayJPL3ietm+Pu9KLABrLCK2hqOF9CxH/rSJ9Hl35UgvZtdxE/n0ZxLEtIk8zZHOm0ivcqST9uPl16Qq/SdHOstRf5kj70bEVumfBwCXqKOONjHkl9dJBIOkUKV/dMmhTQz5uIl0lCM/b6Leb2Kyc1US6EYtTaSDHPk4VenvKxLPixx59y5/JgBcop1qqr9cNb3UjRTa0UI+zpEPm0gH7VXvd4mhjjp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42t/ti8EoDgJpLyI2FrcD8t5H8DoLSYQc+1lRMRWrtK3uUrTHPW/JQ9g9Ja30jDfDsA1XHcvJgAYWN4m4/LDjADgwk3OowCAgYUSUueiA3A9OdLJdY9UBYALuUpfD0Yh25NPSscEwBpI1eSP/S3FrzpWFQAuLJfy5tPSMQGwBpYrsfK0ifxV6bgAWAOLC+lN5Gmq6i9KxwXAyDUx2Vnc0C9HmuZIZznSiyeP6qelYwRgpPpd6cMtxS92h7W4DsBqjz94vN1EfbRqSitHPi4dHwBrIiK22iNW04EGQwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4DL/B7EdVIEgTgUAAAAAAElFTkSuQmCC

This generates a blank PDF page instead of adding a green square:

require_once('tcpdf_include.php');
$pdf = new TCPDF();
$pdf->AddPage();
$img_encoded ='iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAANklEQVR42u3OQQ0AAAgEoDO50TWFmw9IQGXSeawEBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQVvLDGRO9mhGZRRAAAAAElFTkSuQmCC';
$imgdata = base64_decode($img_encoded);
$pdf->Image('@'.$imgdata);
$pdf->Output('example_009.pdf', 'I');

I've validated the base64 code (https://base64.guru/converter/decode/image) and the full base64 images load correctly in a browser: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAACWCAYAAADwkd5lAAAI2UlEQVR4nO3dMW8cxxUAYP0E/gT9AJv7JN/OrIAAYm0EIEt3YhGktVwGCGB2MZDCRKp0ZpO0YpMmhaUfYEAsXKQJKATpUpCAgTg2nFyKveXt3h1pUhI5e7zvAxYiyDvqiRT27cy8N/PgAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABsvDrqePKofvrkUf20ieZh6XgAGIkmmodNTHZy5N0m0uc50osm8ssc6ayJPL3ietm+Pu9KLABrLCK2hqOF9CxH/rSJ9Hl35Ug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+BrGoe7G+1r/oKGI3hzUkCuWs50jfdIVF5RWXVsGzX4jkwIhJIWcNtZIYJpI769/0TCK9qMAS4c/pAylpeA2kXxxcX13Okcwd9AaOStyef9Kp7/lk6nk2zfGRtvb88bZV+kjyA0Zlv5Z6nOZLu5ju2tA9Wlb5fnLayaA6M0uJUSel4NtGK42t/ti8EoDgJpLyI2FrcD8t5H8DoLSYQc+1lRMRWrtK3uUrTHPW/JQ9g9Ja30jDfDsA1XHcvJgAYWN4m4/LDjADgwk3OowCAgYUSUueiA3A9OdLJdY9UBYALuUpfD0Yh25NPSscEwBpI1eSP/S3FrzpWFQAuLJfy5tPSMQGwBpYrsfK0ifxV6bgAWAOLC+lN5Gmq6i9KxwXAyDUx2Vnc0C9HmuZIZznSiyeP6qelYwRgpPpd6cMtxS92h7W4DsBqjz94vN1EfbRqSitHPi4dHwBrIiK22iNW04EGQwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4DL/B7EdVIEgTgUAAAAAAElFTkSuQmCC

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAANklEQVR42u3OQQ0AAAgEoDO50TWFmw9IQGXSeawEBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQVvLDGRO9mhGZRRAAAAAElFTkSuQmCC

I know from a few postings people have recommending embedding the base64 image in an <img> tag and then writing as HTML, though I'm looking to use the base64 image directly as an image.

Any ideas on why the base64 from the example works, but all others fail?


Solution

  • This was a folder issue with the K_PATH_CACHE variable.

    With more experimentation, I found that any PNG file would not be added to the PDF which had me looking into the tcpdf.php file. This led to the error log and ultimately to the constant K_PATH_CACHE.

    The imgpng() function uses K_PATH_CACHE to define the location for /tmp in the PHP installation (Bitnami through a AWS Lightsail), but the location was defined incorrectly.

    The default value for K_PATH_CACHE was set to /opt/bitnami/php/tmp but that folder was empty. The actual tmp folder is found at /tmp.

    To resolve this, I redefined the location for K_PATH_CACHE to be the actual /tmp directory in a config file loaded before everything else:

    define('K_PATH_CACHE', '/tmp/');

    PNGs now load, both from a base64 string and when loaded as a file.

    I hope this saves someone a few hours of searching!