mididelight
03-16-2006, 08:30 AM
Hello,
I am using the script found on this page (http://www.devnetwork.net/forums/viewtopic.php?t=41743) to take a very large image and use php to make it smaller. I actually am doing it twice, once to resize the image to the "enlarge" version and then again to make a thumbnail of that. Everything works great in Firefox but when I try to upload the image and run the script in IE 6.0/win I get an unforunate error.
It says imagesx($i): argument supplied is not a valid image. ( I paraphrased ). Here is the code I am using. I am not sure what is going on here. Why would IE bail? This isnt CSS, why should the browser I'm using matter?
<?php
if ($_POST["upload"] == "upload") {
$category = $_POST["category"];
// Connect to DB to get image name
dbConnect('dbname');
// SQL
$sql = mysql_query(" SQL QUERY");
// Get Name
while ($row = mysql_fetch_array($sql)) {
$num = $row["name"] + 1;
}
// Concatenate folder name and file name
$newthumbname = "../images/".$category."/".$num.".jpg";
$newenlargename = "../images/".$category."/large/".$num.".jpg";
// ================================== Create Large Image ================================
// Get Image Properties
$filename = $_FILES['imagefile']['name'];
$temporary_name = $_FILES['imagefile']['tmp_name'];
$mimetype = $_FILES['imagefile']['type'];
$filesize = $_FILES['imagefile']['size'];
// Create Image from MIME Type
switch($mimetype) {
case "image/jpg":
case "image/jpeg":
$i = imagecreatefromjpeg($temporary_name);
break;
case "image/gif":
$i = imagecreatefromgif($temporary_name);
break;
case "image/png":
$i = imagecreatefrompng($temporary_name);
break;
}
// Set Width and Height
$dest_x = 430; //width
$dest_y = 400; //height
// Get Ratio
if (imagesx($i) > $dest_x or imagesy($i) > $dest_y) {
$enlarge_x = $dest_x;
$enlarge_y = imagesy($i)*($dest_x/imagesx($i));
} else {
$enlarge_x = imagesx($i);
$enlarge_y = imagesy($i);
}
// Create New Image
$enlarge = imagecreatetruecolor($dest_x,$dest_y);
// Resize it
imagecopyresampled($enlarge, $i ,0, 0, 0, 0, $enlarge_x, $enlarge_y, imagesx($i), imagesy($i));
// Save It
imagejpeg($enlarge, $newenlargename, 80);
// ================================== Create Thumbnail ================================
//unlink($temporary_name);
// Set Width and Height
$tdest_x = 100; //width
$tdest_y = 66; //height
// Get Ratio
if (imagesx($i) > $tdest_x or imagesy($i) > $tdest_y) {
$thumb_x = $tdest_x;
$thumb_y = imagesy($i)*($tdest_x/imagesx($i));
} else {
$thumb_x = imagesx($i);
$thumb_y = imagesy($i);
}
// Create New Image
$thumb = imagecreatetruecolor($tdest_x,$tdest_y);
// Resize it
imagecopyresampled($thumb, $i ,0, 0, 0, 0, $thumb_x, $thumb_y, imagesx($i), imagesy($i));
// Save It
imagejpeg($thumb, $newthumbname, 80);
// Insert into DB
$insert = mysql_query(" INSERT INTO gallery (name, category, active) VALUES ('$num', '$category', '0') ") or die( "<b>Error:</b> Something went wrong, could not edit link status.". mysql_error());
if ($insert) { echo "<p><strong>New Image Uploaded</strong></p>"; }
// Close DB
@mysql_close($dbcnx);
}
?>
I might be using this wrong, but I basically go through the script twice, so I can create both of my images.
Any ideas?
I am using the script found on this page (http://www.devnetwork.net/forums/viewtopic.php?t=41743) to take a very large image and use php to make it smaller. I actually am doing it twice, once to resize the image to the "enlarge" version and then again to make a thumbnail of that. Everything works great in Firefox but when I try to upload the image and run the script in IE 6.0/win I get an unforunate error.
It says imagesx($i): argument supplied is not a valid image. ( I paraphrased ). Here is the code I am using. I am not sure what is going on here. Why would IE bail? This isnt CSS, why should the browser I'm using matter?
<?php
if ($_POST["upload"] == "upload") {
$category = $_POST["category"];
// Connect to DB to get image name
dbConnect('dbname');
// SQL
$sql = mysql_query(" SQL QUERY");
// Get Name
while ($row = mysql_fetch_array($sql)) {
$num = $row["name"] + 1;
}
// Concatenate folder name and file name
$newthumbname = "../images/".$category."/".$num.".jpg";
$newenlargename = "../images/".$category."/large/".$num.".jpg";
// ================================== Create Large Image ================================
// Get Image Properties
$filename = $_FILES['imagefile']['name'];
$temporary_name = $_FILES['imagefile']['tmp_name'];
$mimetype = $_FILES['imagefile']['type'];
$filesize = $_FILES['imagefile']['size'];
// Create Image from MIME Type
switch($mimetype) {
case "image/jpg":
case "image/jpeg":
$i = imagecreatefromjpeg($temporary_name);
break;
case "image/gif":
$i = imagecreatefromgif($temporary_name);
break;
case "image/png":
$i = imagecreatefrompng($temporary_name);
break;
}
// Set Width and Height
$dest_x = 430; //width
$dest_y = 400; //height
// Get Ratio
if (imagesx($i) > $dest_x or imagesy($i) > $dest_y) {
$enlarge_x = $dest_x;
$enlarge_y = imagesy($i)*($dest_x/imagesx($i));
} else {
$enlarge_x = imagesx($i);
$enlarge_y = imagesy($i);
}
// Create New Image
$enlarge = imagecreatetruecolor($dest_x,$dest_y);
// Resize it
imagecopyresampled($enlarge, $i ,0, 0, 0, 0, $enlarge_x, $enlarge_y, imagesx($i), imagesy($i));
// Save It
imagejpeg($enlarge, $newenlargename, 80);
// ================================== Create Thumbnail ================================
//unlink($temporary_name);
// Set Width and Height
$tdest_x = 100; //width
$tdest_y = 66; //height
// Get Ratio
if (imagesx($i) > $tdest_x or imagesy($i) > $tdest_y) {
$thumb_x = $tdest_x;
$thumb_y = imagesy($i)*($tdest_x/imagesx($i));
} else {
$thumb_x = imagesx($i);
$thumb_y = imagesy($i);
}
// Create New Image
$thumb = imagecreatetruecolor($tdest_x,$tdest_y);
// Resize it
imagecopyresampled($thumb, $i ,0, 0, 0, 0, $thumb_x, $thumb_y, imagesx($i), imagesy($i));
// Save It
imagejpeg($thumb, $newthumbname, 80);
// Insert into DB
$insert = mysql_query(" INSERT INTO gallery (name, category, active) VALUES ('$num', '$category', '0') ") or die( "<b>Error:</b> Something went wrong, could not edit link status.". mysql_error());
if ($insert) { echo "<p><strong>New Image Uploaded</strong></p>"; }
// Close DB
@mysql_close($dbcnx);
}
?>
I might be using this wrong, but I basically go through the script twice, so I can create both of my images.
Any ideas?