1

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
CJ Dennis
  • 4,226
  • 2
  • 40
  • 69
Mohammad Hosseini
  • 1,649
  • 1
  • 16
  • 31
  • check if this post helps you https://stackoverflow.com/questions/31844401/gd-png-cannot-allocate-image-data – Giacomo M Aug 19 '19 at 08:06
  • @GiacomoM I checked the post.....in phpInfo() gd writes "GD Version bundled (2.1.0 compatible)" but in my CentoOS server in gdlib root is "usr/lib64/libgd.so.2.0.0" – Mohammad Hosseini Aug 19 '19 at 08:39

0 Answers0