imagecreatefrompng
works fine in my localhost but when I upload my code in server it doesn't work. I try to know where is the error and I get False
when var_dump imagecreatefrompng
in the server but in localhost return True
The main error is:
imagepng(): gd-png error: cannot allocate
libpng
main struct
My code:
<?php
$final_w = 600;
$final_h = 400;
$resize_width = min($final_h,$final_w);
$resize_height = min($final_h,$final_w);
$padding = (max($final_h,$final_w) - min($final_h,$final_w))/2;
header('Content-Type: image/png');
$image = imagecreate($final_w,$final_h);
$white = imagecolorallocatealpha( $image, 255, 255, 255 , 0 );
imagealphablending($image,true);
$image_2 = imagecreatefrompng('logo.png');
$image_3 = imagescale($image_2,$resize_width,$resize_height);
if ($final_w > $final_h) {
$new = imagecopy($image, $image_3, $padding, 0, 0, 0, $resize_width, $resize_height);
} else
{
$new = imagecopy($image, $image_3, 0, $padding, 0, 0, $resize_width, $resize_height);
}
imagepng($image);
Localhost xampp config:
- PHP Version 7.2.5
- libPNG Version 1.6.34
Server config:
- CentoOS
- PHP Version 7.2.12
- libPNG Version 1.5.13