$vdir_upload = FCPATH.'public/images/logo_theme/';
$vfile_upload = $vdir_upload . $this->upload->file_name;
switch($this->upload->file_ext)
{
case '.jpg':
case '.jpeg':
$im_src = imagecreatefromjpeg($vfile_upload);
break;
case '.gif':
$im_src = imagecreatefromgif($vfile_upload);
break;
case '.png':
$im_src = imagecreatefrompng($vfile_upload);
break;
default:
$im_src = false;
break;
}
$src_width = imageSX($im_src);
$src_height = imageSY($im_src);
$dst_width = 120;
$dst_height = 20;
$im = imagecreatetruecolor($dst_width,$dst_height);
//==========================================
$trnprt_indx = imagecolortransparent($im_src);
// If we have a specific transparent color
if ($trnprt_indx >= 0) {
// Get the original image's transparent color's RGB values
$trnprt_color = imagecolorsforindex($im_src, $trnprt_indx);
// Allocate the same color in the new image resource
$trnprt_indx = imagecolorallocate($im, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
// Completely fill the background of the new image with allocated color.
imagefill($im, 0, 0, $trnprt_indx);
// Set the background color for new image to transparent
imagecolortransparent($im, $trnprt_indx);
}
// Always make a transparent background color for PNGs that don't have one allocated already
elseif ($this->upload->file_ext == '.png') {
// Turn off transparency blending (temporarily)
imagealphablending($im, false);
// Create a new transparent color for image
$color = imagecolorallocatealpha($im, 0, 0, 0, 127);
// Completely fill the background of the new image with allocated color.
imagefill($im, 0, 0, $color);
// Restore transparency blending
imagesavealpha($im, true);
}
//===========================================
imagecopyresampled($im, $im_src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
switch($this->upload->file_ext)
{
case '.jpg':
case '.jpeg':
imagejpeg($im,$vdir_upload . "mobile_" . $this->upload->file_name);
break;
case '.gif':
imagegif($im,$vdir_upload . "mobile_" . $this->upload->file_name);
break;
case '.png':
imagepng($im,$vdir_upload . "mobile_" . $this->upload->file_name);
break;
default:
break;
}
imagedestroy($im_src);
imagedestroy($im);
Tidak ada komentar:
Posting Komentar