1

I got trouble by using GD Imagepng() on my server. My code work well on my local computer, create the file correctly, save it correctly, but not on my server.

I looked lot of posts and try lot of things without success. All GD Elements are enabled. If I output the picture directly in a page without trying to save it, it work but as soon as I try to save it, it not worked anymore. Permission on the 'custom' folder are set to 777. My php file is coded id ANSI.

Here is my code:

function random($car) {
    $string = "";
    $chaine = "abcdefghijklmnpqrstuvwxy1234567890";
    srand((double)microtime()*1000000);
    for($i=0; $i<$car; $i++) {
        $string .= $chaine[rand()%strlen($chaine)];
    }
    return $string;
}


$pathPictures = Array();
$pathSmall = "images/custom/pure/166x250/";
$pathMid = "images/custom/pure/464x700/";
$pathBig = "images/custom/pure/1770x2668/";
array_push($pathPictures, $pathSmall, $pathMid, $pathBig);

$sizes=Array('166x250', '464x700' ,'1770x2668');
$colorRGB = explode(',', str_replace(array('rgb(', ')'), '', $_POST["selectedColor"]));

$selectedPictures = Array();
array_push($selectedPictures, $_POST["selectedStringerImg"]);
array_push($selectedPictures, $_POST["selectedGraphicImg"]);
array_push($selectedPictures, $_POST["selectedFinsFuturesLeftImg"]);
array_push($selectedPictures, $_POST["selectedFinsFuturesCenterImg"]);
array_push($selectedPictures, $_POST["selectedFinsFuturesRightImg"]);
array_push($selectedPictures, $_POST["selectedFinsFCSImg"]);
array_push($selectedPictures, "mask-pure.png");

$pixName = random(25);

for($a=0;$a<=2;$a++){
    $size = explode('x', $sizes[$a]);
    $x=$size[0];
    $y=$size[1];
    $final_img = imagecreatetruecolor($x, $y);
    $color = imagecolorallocatealpha($final_img, $colorRGB[0], $colorRGB[1], $colorRGB[2], 0);
    imagefill($final_img, 0, 0, $color);

    foreach($selectedPictures as $pix){
     $image = imagecreatefrompng($pathPictures[$a].$pix);
     imagecopy($final_img, $image, 0, 0, 0, 0, $x, $y);
        imagealphablending($image, false);
        imagesavealpha($image, true);
    };
    imagepng($final_img, $pathPictures[$a].'custom/'.$pixName.'.png');
};
echo $pathSmall.'custom/'.$pixName.'.png';

Thanks for your help and have a nice day !

Damien Pirsy
  • 25,319
  • 8
  • 70
  • 77
  • Are the file permissions in the relevant subdirectories of custom/ also set to 777? Just setting them on custom/ is not enough. (By the way, 777 permissions are always dangerous to use, though it can be useful for testing.) – asmecher Jun 12 '13 at 19:08
  • So what error do you see either on screen or in the logs? – Danack Jun 16 '13 at 21:14
  • I'm having the same problem. No errors, nothing in the logs. – halfpastfour.am Jan 06 '14 at 15:48

0 Answers0