Cool man, that's great news. I was just looking at Yahoo image upload deal and see that they can do it as well.
Ok, here's my code. I can upload an image and resize it and copy it no problem, but my errors are coming when I try to resize and copy the image twice.
Here is the function I use to resize and copy the image.
// Upload and resize photo ---------
function jpgResizeUpload($source, $dsrdWidth, $dsrdHeight, $uploadDir, $dsrdImgName, $quality = 70){
/* Check for the image's exisitance */
if (!file_exists($source)){
}else{
list($imageW, $imageH, $type, $attrib) = getimagesize($source); // get variables for image width and height
$size = getimagesize($source); // Get the image dimensions and mime type
// check image size to make sure it's under desired width x desired height
if((($imageW > $dsrdWidth) || ($imageH > $dsrdHeight)) && ($type == "2")) { // image width or height is greater than what you want
if($imageH > $imageW) {
$ratio = ($imageH/$imageW);
$newH = $dsrdHeight;
$newW = ($newH/$ratio);
}//end if
if($imageW > $imageH) {
$ratio = ($imageW / $imageH);
$newW = $dsrdWidth;
$newH = ($newW/$ratio);
}//end if
if($imageW == $imageH) {
$ratio = "1";
$newW = $dsrdHeight;
$newH = $dsrdHeight;
}//end if
$resize = imagecreatetruecolor($newW, $newH); // Create a blank image
switch ($size['mime']){
case 'image/jpeg':
$im = imagecreatefromjpeg($source);
imagecopyresampled($resize, $im, 0, 0, 0, 0, $newW, $newH, $size[0], $size[1]); // Resample the original JPEG
$newFileName1 = "$uploadDir/$dsrdImgName";
imagejpeg($resize, $newFileName1, $quality);
break;
case 'image/png':
$im = imagecreatefrompng($source);
imagecopyresampled($resize, $im, 0, 0, 0, 0, $newW, $newH, $size[0], $size[1]); // Resample the original PNG
imagepng($resize, '', $quality); // Output the new PNG
break;
}//end switch
imagedestroy($im);
}else{ //image wasn't too big (or was format other than jpeg)... upload as normal
copy($source, "$uploadDir/$dsrdImgName");
}//end if
}//end if
}//end uploadResize
And here is how I am trying to use it
foreach($_FILES as $Image){
$imageTempName = $Image['tmp_name'];
$imageName = $Image['name'];
$imageType = $Image['type'];
if (!empty($imageName)){
if ($imageType != "image/pjpeg" AND $imageType != "image/jpeg"){
$se->errorMessage("error.php","Image must be in .jpg format.","addbefore2.php");
exit();
}//end if
}//end if
$time = time();
//resize, rename and copy Full Image
$fullPath = "/home/httpd/vhosts/collisionsite.com/httpdocs/webadmin/accountimages/$accountID";
$photo->jpgResizeUpload($imageTempName, "800","600", $fullPath, $time.".jpg");
$time+=1;
// Error is coming on this line when I try to fool with the image again $thumbphoto->jpgResizeUpload($imageTempName, "200","600", $fullPath, $time.".jpg");
if($imageTempName) unlink ($imageTempName);
if($imageName == NULL){
$imageNameArray[]="";
}else{
$imageNameArray[]=$time;
}//end if
sleep(1);
}//end for
If you can help me out I appreciate it!