9

The following code works on my laptop but doesn't work on remote server:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

$filename = "../../content/".base64_decode($_GET["file"]);


$ext = pathinfo($filename, PATHINFO_EXTENSION);

if ($ext=="jpg" || $ext=="jpeg") {
$image_s = imagecreatefromjpeg($filename);
} else if ($ext=="png") {
$image_s = imagecreatefrompng($filename);
}

$width = imagesx($image_s);
$height = imagesy($image_s);


$newwidth = 285;
$newheight = 232;

$image = imagecreatetruecolor($newwidth, $newheight);
imagealphablending($image,true);
imagecopyresampled($image,$image_s,0,0,0,0,$newwidth,$newheight,$width,$height);

// create masking
$mask = imagecreatetruecolor($width, $height);
$mask = imagecreatetruecolor($newwidth, $newheight);



$transparent = imagecolorallocate($mask, 255, 0, 0);
imagecolortransparent($mask, $transparent);



imagefilledellipse($mask, $newwidth/2, $newheight/2, $newwidth, $newheight, $transparent);



$red = imagecolorallocate($mask, 0, 0, 0);
imagecopy($image, $mask, 0, 0, 0, 0, $newwidth, $newheight);
imagecolortransparent($image, $red);
imagefill($image,0,0, $red);

// output and free memory
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
imagedestroy($mask);
?>

It shows the following image on my laptop: https://i.stack.imgur.com/Aai1r.png

And this is how it's shown on remote server: https://i.stack.imgur.com/77fbV.png

What do you think? What's a problem?

Adil Aliyev
  • 1,159
  • 2
  • 9
  • 22
  • 2
    Do you have different GD versions on your server than your local env? That's almost certainly the problem. It might also be linked to the transparency. – haltabush Mar 26 '12 at 22:06
  • local env has the GD 2.0 version, and on the server 2.0.38. Both supports transparency. – Adil Aliyev Mar 26 '12 at 22:11

3 Answers3

14

Changed the line:

imagecopy($image, $mask, 0, 0, 0, 0, $newwidth, $newheight);

to:

imagecopymerge($image, $mask, 0, 0, 0, 0, $newwidth, $newheight,100);
Adil Aliyev
  • 1,159
  • 2
  • 9
  • 22
2

I think a basic reading of how to debug http://blog.regehr.org/archives/199 would be useful to you, and help you to solve your problem

Toby Allen
  • 10,997
  • 11
  • 73
  • 124
-1

I think you might have problems with filepath. Check if pathinfo returns valid extension and add after $filename declaration something to check if it exists and is readable

if(!is_file($file) || !is_readable($file)){ die('Readable file not found');}
Artjom Kurapov
  • 6,115
  • 4
  • 32
  • 42