GD: php imagepng creates spaces in the image

I have a problem with GD when I create images with php.

It is strange that it works on the same server with php version 5.3.1, but not on php version 5.2.14. (I'm not sure if this is the version of php or GD lib that does this.)

alt text This file is created with conversion and stored in the directory in captcha::get_file() .

alt text And this file is generated using imagecreatefrompng() and imagepng()

alt text I made small changes to the script and made a gif. But the problem with png

What causes this and how to fix it?

Here is the phpcode:

 <?php session_start(); require_once("./captcha.php")); // creates the image with convert and returns the location of the picture // document_root/picture/picture.png $picloc = captcha::get_file(); $image = @imagecreatefrompng($picloc); header('Content-type: image/png'); imagepng($image); imagedestroy($image); unlink($picloc); ?> 
+4
source share
1 answer

not positive, but the problem may be in the content length header.

 header('Content-Length: ' . strlen($image)); 

at the moment of your code, $ image is the data type of the resource, not a string. just try removing the title bar of the content length and see what happens.

0
source

Source: https://habr.com/ru/post/1335147/


All Articles