kinkstar
%Europe/Berlin %557 %2009, 13:22
he lui,
ik heb een script gekregen om plaatjes te uploaden/resizen maar ik kwam er achter dat de png's transparantie niet behouden blijft... bij alle andere plaatjes werkt het gewoon alleen met transparantie niet.
nu heb ik wat op google gevonden maar ik weet niet echt waar ik dit in mijn script zou moeten plaatsen:
het script wat er bij moet:
imagealphablending($file, false);
imagesavealpha($file,true);
$transparent = imagecolorallocatealpha($file, 255, 255, 255, 127);
imagefilledrectangle($file, 0, 0, $_GET['toWidth'], $_GET['toHeight'], $transparent);
mijn code:
if (is_uploaded_file($_FILES["Filedata"]["tmp_name"])){
$timestamp = time();
$filename = $timestamp.str_replace(" ","_",str_replace("'","",$_FILES["Filedata"]["name"]));
copy($_FILES["Filedata"]["tmp_name"], "upload/".$timestamp.str_replace(" ","_",str_replace("'","",$_FILES["Filedata"]["name"])));
include(xxx);
$my_connection = mysql_connect($db_host,$db_user,$db_pass) or die("Er is een fout opgetreden in de MySQL database:" .mysql_error());
mysql_select_db($db_name) or die('Line: '.__LINE__.': '.mysql_error());
if($_GET['type'] == 'image') {
$fileExt = explode('.',$filename);
$save = "upload/".$filename;
$saveThumb = "upload/thumbnails/".$filename;
$file = "upload/".$filename;
$needsedit = false;
list($width, $height) = getimagesize($file);
$ratio = $height/$width;
if(($_GET['heightVar']/$_GET['widthVar']) != $ratio) {
$needsedit = true;
}else{
$modwidth = $_GET['widthVar'];
$modheight = $_GET['heightVar'];
$tn = imagecreatetruecolor($modwidth, $modheight) ;
if(preg_match('/jpg|jpeg/',$fileExt[1])) {
$image = imagecreatefromjpeg($file) ;
}
if(preg_match('/gif/',$fileExt[1])) {
$image = imagecreatefromgif($file) ;
}
if(preg_match('/png/',$fileExt[1])) {
$image = imagecreatefrompng($file) ;
}
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
if(preg_match('/jpg|jpeg/',$fileExt[1])) {
imagejpeg($tn, $save, 100) ;
}
if(preg_match('/gif/',$fileExt[1])) {
imagegif($tn, $save) ;
}
if(preg_match('/png/',$fileExt[1])) {
imagepng($tn, $save, 9) ;
}
$thumb = imagecreatetruecolor(112, 112*$ratio);
imagecopyresampled($thumb, $image, 0, 0, 0, 0, 112,112*$ratio, $width, $height);
if(preg_match('/jpg|jpeg/',$fileExt[1])) {
imagejpeg($thumb, $saveThumb, 75) ;
}
if(preg_match('/gif/',$fileExt[1])) {
imagegif($thumb, $saveThumb) ;
}
if(preg_match('/png/',$fileExt[1])) {
imagepng($thumb, $saveThumb, 7) ;
}
}
}
ik heb een script gekregen om plaatjes te uploaden/resizen maar ik kwam er achter dat de png's transparantie niet behouden blijft... bij alle andere plaatjes werkt het gewoon alleen met transparantie niet.
nu heb ik wat op google gevonden maar ik weet niet echt waar ik dit in mijn script zou moeten plaatsen:
het script wat er bij moet:
imagealphablending($file, false);
imagesavealpha($file,true);
$transparent = imagecolorallocatealpha($file, 255, 255, 255, 127);
imagefilledrectangle($file, 0, 0, $_GET['toWidth'], $_GET['toHeight'], $transparent);
mijn code:
if (is_uploaded_file($_FILES["Filedata"]["tmp_name"])){
$timestamp = time();
$filename = $timestamp.str_replace(" ","_",str_replace("'","",$_FILES["Filedata"]["name"]));
copy($_FILES["Filedata"]["tmp_name"], "upload/".$timestamp.str_replace(" ","_",str_replace("'","",$_FILES["Filedata"]["name"])));
include(xxx);
$my_connection = mysql_connect($db_host,$db_user,$db_pass) or die("Er is een fout opgetreden in de MySQL database:" .mysql_error());
mysql_select_db($db_name) or die('Line: '.__LINE__.': '.mysql_error());
if($_GET['type'] == 'image') {
$fileExt = explode('.',$filename);
$save = "upload/".$filename;
$saveThumb = "upload/thumbnails/".$filename;
$file = "upload/".$filename;
$needsedit = false;
list($width, $height) = getimagesize($file);
$ratio = $height/$width;
if(($_GET['heightVar']/$_GET['widthVar']) != $ratio) {
$needsedit = true;
}else{
$modwidth = $_GET['widthVar'];
$modheight = $_GET['heightVar'];
$tn = imagecreatetruecolor($modwidth, $modheight) ;
if(preg_match('/jpg|jpeg/',$fileExt[1])) {
$image = imagecreatefromjpeg($file) ;
}
if(preg_match('/gif/',$fileExt[1])) {
$image = imagecreatefromgif($file) ;
}
if(preg_match('/png/',$fileExt[1])) {
$image = imagecreatefrompng($file) ;
}
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
if(preg_match('/jpg|jpeg/',$fileExt[1])) {
imagejpeg($tn, $save, 100) ;
}
if(preg_match('/gif/',$fileExt[1])) {
imagegif($tn, $save) ;
}
if(preg_match('/png/',$fileExt[1])) {
imagepng($tn, $save, 9) ;
}
$thumb = imagecreatetruecolor(112, 112*$ratio);
imagecopyresampled($thumb, $image, 0, 0, 0, 0, 112,112*$ratio, $width, $height);
if(preg_match('/jpg|jpeg/',$fileExt[1])) {
imagejpeg($thumb, $saveThumb, 75) ;
}
if(preg_match('/gif/',$fileExt[1])) {
imagegif($thumb, $saveThumb) ;
}
if(preg_match('/png/',$fileExt[1])) {
imagepng($thumb, $saveThumb, 7) ;
}
}
}