Reputation: 1070
code updated
here's the code i'm using to upload. Using a class and then refer to it while uploading. The problem is as we know (but didn't find a solution yet) is the black background. any way to keep opacity without changing the background color ?
class thumb{
function load($img){
$img_info = getimagesize($img);
$img_type = $img_info[2];
if($img_type == 1){
$this->image = imagecreatefromgif($img);
}
elseif($img_type == 2){
$this->image = imagecreatefromjpeg($img);
}
elseif($img_type == 3){
$this->image = imagecreatefrompng($img);
}
}
function get_height(){
return imagesy($this->image);
}
function get_width(){
return imagesx($this->image);
}
function resize($width,$height){
$img_new = imagecreatetruecolor($width,$height);
imagealphablending($img_new, false);
imagesavealpha($img_new,true);
$transparent = imagecolorallocatealpha($img_new, 255, 255, 255, 127);
imagefilledrectangle($img_new, 0, 0, $width, $height, $transparent);
imagecopyresampled($img_new,$this->image,0,0,0,0,$width,$height,$this->get_width(),$this->get_height());
}
function save($img,$img_type = 'imagetype_jpeg'){
$this->image_type = $img_info[2];
if($img_type == 'imagetype_gif'){
imagegif($this->image,$img);
}
elseif($img_type == 'imagetype_jpeg'){
imagejpeg($this->image,$img);
}
elseif($img_type == 'imagetype_png'){
imagepng($this->image,$img);
}
}
and the code to resize after uploading
$mini_img = new thumb;
$mini_img->load($path.$image);
$mini_img->resize(200,80);
$mini_img->save('../logo_thumb/'.$image);
}
Upvotes: 0
Views: 769
Reputation: 57312
1 you need to set the blending mode to false like
<?php
// Create image
$im = yourimage;
// Set alphablending to on
imagealphablending($im, false);
and than
imagesavealpha($im,true);
Upvotes: 1