Hello!
I'm hoping someone can help me with this script (thumb_pro.php). It works in IE but in FF, Mozilla and Netscape it creates this error:
"The image “http//www.mypage/thumb_pro.php” cannot be displayed, because it contains errors"
The script is on an intermediate page it is only there to create thumbnails of jpegs that have just been uploaded by the previous page. I put the script on an intermediate page to try and surpress the error.
When I comment out
header("Content-type: image/jpeg");
The error goes away.
Many thanks!
Chris
<?php
if (!isset($_SESSION)) {
session_start();
}
//Gets Event Data
$event_id = $_SESSION['eventID'];
$event_dir = 'images/event_images/EVENT_' . $event_id;
$thumbs = $event_dir . '/thumbnails/';
$open_dir = opendir($event_dir);
//Checks to see if the thumbnails exist
if(!file_exists($thumbs)){
mkdir($thumbs, 0777);
//Creates thumbnails
while(false !== ($image_name = readdir($open_dir))){
if (is_file($event_dir . '/' . $image_name)){
if(preg_match('/\.(jpg|jpeg)/i', $image_name)){
$image_path = $event_dir . '/' . $image_name;
$thumb_path = $thumbs . $image_name;
define(MAX_WIDTH, 200);
define(MAX_HEIGHT, 200);
// Get image location
$image_path = $event_dir .'/'. $image_name;
$img = null;
$ext = strtolower(end(explode('.', $image_path)));
if ($ext == 'jpg' || $ext == 'jpeg') {
$img = @imagecreatefromjpeg($image_path);
}
// If an image was successfully loaded, test the image for size
if ($img) {
// Get image size and scale ratio
$width = imagesx($img);
$height = imagesy($img);
$scale = min(MAX_WIDTH/$width, MAX_HEIGHT/$height);
// If the image is larger than the max shrink it
if ($scale < 1) {
$new_width = floor($scale*$width);
$new_height = floor($scale*$height);
// Create a new temporary image
$tmp_img = imagecreatetruecolor($new_width, $new_height);
// Copy and resize old image into new image
imagecopyresized($tmp_img, $img, 0, 0, 0, 0,
$new_width, $new_height, $width, $height);
imagedestroy($img);
$img = $tmp_img;
}
}
$perm_thumb = $thumbs . $image_name;
header("Content-type: image/jpeg"); /* This seems to be causing the problem */
imagejpeg($img,$perm_thumb,'100');
}
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language=javascript>
setTimeout("location.href='http://www.mypage.com/image_finder.php'", 0);
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Thumb Processor</title>
</head>
<body>
</body>
</html>