사용자가 업로드 할 수있는 페이지가 있습니다. 사진을 업로드 할 때 서버로 업로드하는 동안 사진의 크기가 조정됩니다. 내가 이미지 크기를 조정하는 PHP를 사용하고 있지만 문제는 사용자가 애니메이션 GIF를 업로드 할 때 애니메이션이 손실되고 내가 프레임을 서버에 저장되지 않는 것을 확인했을 때입니다. 그래서 어쨌든 우리는 애니메이션을 가진 크기가 조정 된 이미지가 보여 질 수 있도록 PHP를 사용하여 프레임을 저장할 수 있습니다. 또한 사용자가 업로드하는 이미지가 애니메이션인지 또는 PHP를 사용하지 않는지 식별하는 방법도 있습니다.크기를 조정할 때 애니메이션 GIF 프레임 저장
class resizeimage{
var $type;
var $width;
var $height;
var $resize_width;
var $resize_height;
var $cut;
var $srcimg;
var $dstimg;
var $im;
var $fill;
function resizeimage($img, $image_type, $target, $wid, $hei,$c = 0, $qu = 75, $fill = '')
{
$this->srcimg = $img;
$this->fill = $fill;
$this->resize_width = $wid;
$this->resize_height = $hei;
$this->cut = $c;
if (eregi("jpg",$image_type) || eregi("jpeg",$image_type)) {
$this->type="jpg";
}
elseif (eregi("gif",$image_type)) {
$this->type="gif";
}
elseif (eregi("png",$image_type) || eregi("png",$image_type)) {
$this->type="png";
}
else {
echo "Not Supported File";
exit();
}
$this->initi_img();
$this -> dst_img($target);
$this->width = imagesx($this->im);
$this->height = imagesy($this->im);
// add by stan
if (!$this->resize_height) {
$this->resize_height = $this->resize_width*($this->height/$this->width);
}
if (!$this->resize_width) {
$this->resize_width = $this->resize_height*($this->width/$this->height);
}
$this->newimg($qu);
ImageDestroy ($this->im);
}
function newimg($qu)
{
$resize_ratio = ($this->resize_width)/($this->resize_height);
$ratio = ($this->width)/($this->height);
if ($ratio>=$resize_ratio) {
$offset_x = 0;
$offset_y = ceil(($this->resize_height - $this->resize_width/$ratio)/2);
$copy_width = $this->resize_width;
$copy_height = $this->resize_height/$ratio;
}
else {
$offset_y = 0;
$offset_x = ceil(($this->resize_width-$this->resize_height*$ratio)/2);
$copy_width = $this->resize_height*$ratio;
$copy_height = $this->resize_height;
}
if(($this->cut)=="1")
{
if($ratio>=$resize_ratio)
{
$newimg = imagecreatetruecolor($this->resize_width,$this->resize_height);
imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width,$this->resize_height, (($this->height)*$resize_ratio), $this->height);
ImageJpeg ($newimg,$this->dstimg,$qu);
}
if($ratio<$resize_ratio)
{
$newimg = imagecreatetruecolor($this->resize_width,$this->resize_height);
imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->width, (($this->width)/$resize_ratio));
ImageJpeg ($newimg,$this->dstimg,$qu);
}
}
else
{
if ($this->fill == 'black') {
$newimg = imagecreatetruecolor($this->resize_width,$this->resize_height);
$bg = imagecolorallocate($newimg, 0, 0, 0);
imagefill($newimg, 0, 0, $bg);
imagecopyresampled($newimg, $this->im, $offset_x, $offset_y, 0, 0, $copy_width, $copy_height, $this->width, $this->height);
ImageJpeg ($newimg,$this->dstimg,$qu);
}
elseif ($this->fill == 'white') {
$newimg = imagecreatetruecolor($this->resize_width,$this->resize_height);
$bg = imagecolorallocate($newimg, 255, 255, 255);
imagefill($newimg, 0, 0, $bg);
imagecopyresampled($newimg, $this->im, $offset_x, $offset_y, 0, 0, $copy_width, $copy_height, $this->width, $this->height);
ImageJpeg ($newimg,$this->dstimg,$qu);
}
elseif($ratio>=$resize_ratio)
{
$newimg = imagecreatetruecolor($this->resize_width,($this->resize_width)/$ratio);
imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, ($this->resize_width)/$ratio, $this->width, $this->height);
ImageJpeg ($newimg,$this->dstimg,$qu);
}
elseif($ratio<$resize_ratio)
{
$newimg = imagecreatetruecolor(($this->resize_height)*$ratio,$this->resize_height);
imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, ($this->resize_height)*$ratio, $this->resize_height, $this->width, $this->height);
ImageJpeg ($newimg,$this->dstimg,$qu);
}
}
}
function initi_img()
{
if($this->type=="jpg")
{
if (!$this->im = imagecreatefromjpeg($this->srcimg))
die('This is not a pic:'.$this->srcimg);
}
if($this->type=="gif")
{
if (!$this->im = imagecreatefromgif($this->srcimg))
die('This is not a pic:'.$this->srcimg);
}
if($this->type=="png")
{
if (!$this->im = imagecreatefrompng($this->srcimg))
die('This is not a pic:'.$this->srcimg);
}
}
function dst_img($target)
{
$full_length = strlen($this->srcimg);
$type_length = strlen($this->type);
$name_length = $full_length-$type_length;
$name = substr($this->srcimg,0,$name_length-1);
$this->dstimg = $target.".".$this->type;
}
function type() {
return $this->type;
}}
당신은 내가 생각하는 몇 가지 수정을 쓴 GIF 크기 변경 클래스를 사용할 수 있습니다 제안에게
애니메이션 GIF 업로드 또는 일반적으로 모든 GIF를 차단하는 것이 좋습니다 (단, 옵션이 아닌 경우). – Alex