Hi,
Can anyone see what is wrong with this function. The problem is that when it creates the 450px image it comes out black and not in colour like the thumbnail.
Any ideas?
[PHP]<?php
function uploadimage($va lue){
$file_type = $value['type'];
$file_name = $value['name'];
$file_size = $value['size'];
$file_tmp = $value['tmp_name'];
//check file extension
$ext = strrchr($file_n ame,'.');
$ext = strtolower($ext );
//get the file extension.
$getExt = explode ('.', $file_name);
$file_ext = $getExt[count($getExt)-1];
//create a random file name
$rand_name = md5(time());
$rand_name= rand(0,99999999 9);
//get the new width variable.
$ThumbWidth = 150;
$ImgWidth = 450;
//keep image type
if($file_size){
if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
$new_img = imagecreatefrom jpeg($file_tmp) ;
}elseif($file_t ype == "image/x-png" || $file_type == "image/png"){
$new_img = imagecreatefrom png($file_tmp);
}elseif($file_t ype == "image/gif"){
$new_img = imagecreatefrom gif($file_tmp);
}
//list width and height and keep height ratio.
list($width, $height) = getimagesize($f ile_tmp);
$imgratio=$widt h/$height;
if ($imgratio>1){
$newwidth = $ThumbWidth;
$newheight = $ThumbWidth/$imgratio;
$newwidth2 = $ImgWidth;
$newheight2 = $ImgWidth/$imgratio;
}else{
$newheight = $ThumbWidth;
$newwidth = $ThumbWidth*$im gratio;
$newheight2 = $ImgWidth;
$newwidth2 = $ImgWidth*$imgr atio;
}
$resized_img = imagecreatetrue color($newwidth , $newheight);
$resized_img2 = imagecreatetrue color($newwidth 2, $newheight2);
imagecopyresize d($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagecopyresize d($resized_img2 , $new_img, 0, 0, 0, 0, $newwidth2, $newheight2, $width2, $height2);
//save image
move_uploaded_f ile($resized_im g, "uploads/thumbs/$rand_name.$fil e_ext");
move_uploaded_f ile($resized_im g2, "uploads/big/$rand_name.$fil e_ext");
imagejpeg ($resized_img," uploads/thumbs/$rand_name.$fil e_ext");
imagejpeg ($resized_img2, "uploads/big/$rand_name.$fil e_ext");
imagedestroy($r esized_img);
imagedestroy($r esized_img2);
imagedestroy($n ew_img);
}
$value = "$rand_name.$fi le_ext";
return $value;
} ?>[/PHP]
Cheers,
Adam
Can anyone see what is wrong with this function. The problem is that when it creates the 450px image it comes out black and not in colour like the thumbnail.
Any ideas?
[PHP]<?php
function uploadimage($va lue){
$file_type = $value['type'];
$file_name = $value['name'];
$file_size = $value['size'];
$file_tmp = $value['tmp_name'];
//check file extension
$ext = strrchr($file_n ame,'.');
$ext = strtolower($ext );
//get the file extension.
$getExt = explode ('.', $file_name);
$file_ext = $getExt[count($getExt)-1];
//create a random file name
$rand_name = md5(time());
$rand_name= rand(0,99999999 9);
//get the new width variable.
$ThumbWidth = 150;
$ImgWidth = 450;
//keep image type
if($file_size){
if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
$new_img = imagecreatefrom jpeg($file_tmp) ;
}elseif($file_t ype == "image/x-png" || $file_type == "image/png"){
$new_img = imagecreatefrom png($file_tmp);
}elseif($file_t ype == "image/gif"){
$new_img = imagecreatefrom gif($file_tmp);
}
//list width and height and keep height ratio.
list($width, $height) = getimagesize($f ile_tmp);
$imgratio=$widt h/$height;
if ($imgratio>1){
$newwidth = $ThumbWidth;
$newheight = $ThumbWidth/$imgratio;
$newwidth2 = $ImgWidth;
$newheight2 = $ImgWidth/$imgratio;
}else{
$newheight = $ThumbWidth;
$newwidth = $ThumbWidth*$im gratio;
$newheight2 = $ImgWidth;
$newwidth2 = $ImgWidth*$imgr atio;
}
$resized_img = imagecreatetrue color($newwidth , $newheight);
$resized_img2 = imagecreatetrue color($newwidth 2, $newheight2);
imagecopyresize d($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagecopyresize d($resized_img2 , $new_img, 0, 0, 0, 0, $newwidth2, $newheight2, $width2, $height2);
//save image
move_uploaded_f ile($resized_im g, "uploads/thumbs/$rand_name.$fil e_ext");
move_uploaded_f ile($resized_im g2, "uploads/big/$rand_name.$fil e_ext");
imagejpeg ($resized_img," uploads/thumbs/$rand_name.$fil e_ext");
imagejpeg ($resized_img2, "uploads/big/$rand_name.$fil e_ext");
imagedestroy($r esized_img);
imagedestroy($r esized_img2);
imagedestroy($n ew_img);
}
$value = "$rand_name.$fi le_ext";
return $value;
} ?>[/PHP]
Cheers,
Adam
Comment