2012-03-26 13 views
8

Poniższy kod działa na moim laptopie, ale nie działa na zdalnym serwerze:Crop w okręgu (php)

<?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); 
?> 

To pokazuje poniższy obraz na moim laptopie: http://i.stack.imgur.com/Aai1r.png

i to jak to jest pokazane na zdalnym serwerze: http://i.stack.imgur.com/77fbV.png

Co o tym sądzisz? W czym jest problem?

+2

Czy masz różne wersje GD na swoim serwerze, niż lokalny env? To prawie na pewno problem. Może być również powiązany z przejrzystością. – haltabush

+0

local env ma wersję GD 2.0, a na serwerze 2.0.38. Oba wspierają przejrzystość. –

Odpowiedz

11

Zmieniono linię:

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

do:

imagecopymerge($image, $mask, 0, 0, 0, 0, $newwidth, $newheight,100); 
0

Myślę, że możesz mieć problemy z plikami ścieżki. Sprawdź, czy pathinfo zwraca poprawny rozszerzenia i dodać po deklaracji $ filename coś sprawdzić, czy istnieje i jest czytelny

if(!is_file($file) || !is_readable($file)){ die('Readable file not found');} 
+0

Filepath jest OK. –