17. august 2004 - 07:25
Der er
4 kommentarer og
1 løsning
problemer med upload og GD2
Hej Eksperter
Jeg har lavet et billededatabasesystem, hvor folk kan uploade billeder til. Når man upper et billede, skulle der gerne dannes en thumbnail, men det virker ikke ( Virker fint på min egen computer, men ikke på surftown.dk åbenbart... ) Når jeg prøver får jeg underliggende fejl. Er der nogen der har forslag til hvad jeg skal gøre?
Warning: imagesx(): supplied argument is not a valid Image resource in /hsphere/local/home/hejboel/vejentilnettet.dk/test/2408/inc/functions.php on line 47
Warning: imagesy(): supplied argument is not a valid Image resource in /hsphere/local/home/hejboel/vejentilnettet.dk/test/2408/inc/functions.php on line 48
Warning: imagecopyresized(): supplied argument is not a valid Image resource in /hsphere/local/home/hejboel/vejentilnettet.dk/test/2408/inc/functions.php on line 63
Warning: imagedestroy(): supplied argument is not a valid Image resource in /hsphere/local/home/hejboel/vejentilnettet.dk/test/2408/inc/functions.php on line 77
17. august 2004 - 12:22
#3
Her er lidt kode.
---flytter filen fra midlertidig sted til det rigtige bibliotek
$realname = explode(".",$filename);
$realname = $realname[0] . substr(md5(time()),0,10) ."." .$realname[1];
move_uploaded_file($fra, $til);
createthumb($til,"billeder/upload/small_$realname",150,150);
og her er funktionen der resizer billedet
function createthumb($name,$filename,$new_w,$new_h){
global $gd2;
$system=explode(".",strtolower($name));
if (preg_match("/jpg|jpeg/",$system[1])){
$src_img=imagecreatefromjpeg($name);
}
if (preg_match("/png/",$system[1])){
$src_img=imagecreatefrompng($name);
}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y) {
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y) {
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y) {
$thumb_w=$new_w;
$thumb_h=$new_h;
}
if ($gd2==""){
$dst_img=ImageCreate($thumb_w,$thumb_h);
imagecopyresized($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
//imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
}else{
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
}
/*$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);*/
if (preg_match("/png/",$system[1])){
imagepng($dst_img,$filename);
} else {
imagejpeg($dst_img,$filename,75); //gemmer billede og Sætter kvalitet
}
imagedestroy($dst_img);
imagedestroy($src_img);
}