Forum Moderators: coopster
I have a PHP-script that uploads pictures. This picture is then converted to two different pictures (thumbnail and a browsing picture). Problem is that when using IE it converts the image to pjpeg. What happens is that the picture bloats way too big (400 kB picture goes to 1,5 megs).
I check if the picture type is valid (jpeg/pjpeg) and that it is smaller than 600 kB. If the size check is disabled, the image uploads but the size convertion script informs that the memory is overflooded (or something of the like).
Can I change the pjpeg to jpeg somehow? And does this change the size of the file smaller? If it doesn't, I'd like to know can I reduce the size of the pjpeg?
IE is the only browser I have problem with so I'm not too big on rewriting the scripts.
I'll post the relating scripts below:
$type = validImage($_FILES);
if( $type!= FALSE ) {
$target = SITE_DIR."img/residence/image_".$id."/".$imgId.".jpg";
$_FILES['uploaded_file']['tmp_name'];if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $target))
{
$imgLoad = "Image ".basename($FILES['uploaded_file']['name'])." loaded.";
} else {$imgLoad = "Image Load Failed!";
}
$imgResize = resizeImg( $target, 600, 1, 1, $target);
}
------
function validImage($file) {if(!strcmp($file['uploaded_file']['type'], "image/jpeg") ) {
if( $file['uploaded_file']['size'] <= MAX_FILE_SIZE ) {
list($img, $type) = split('[/.-]', $file['uploaded_file']['type']);
return TRUE;
}
}
return FALSE;
}
-----
function resizeImg( $file, $size, $dim, $var, $img_save='' ){// get image properties to array
$aImgProp = getimagesize($file);$pic = imagecreatefromjpeg($file);
$height = $aImgProp[1];
$width = $aImgProp[0];if( $height > 600 ¦¦ $var == 0 ) {
if( $dim == 1 ){
$rel = $width / $height;
$edHeight = $size;
$edWidth = $size * $rel;
} elseif( $dim == 2 ){
$rel = $height / $width;
$edHeight = $size * $rel;
$edWidth = $size;
}
$edImg = imagecreatetruecolor($edWidth, $edHeight);
imagecopyresampled($edImg, $pic, 0, 0, 0, 0, $edWidth+1, $edHeight+1, $width, $height);
imagejpeg($edImg, $img_save);}
return TRUE;}
Sorry about the lenghty post.
I am currently just advising everybody using the script not to use IE. Problem is that on later implementations I cannot do that.
If anyone finds out a way to either:
1) Change the file type to jpeg
2) Make the pjpeg file smaller
I'd sure appreciate the help.
And I am quite baffled. I've been basically ignoring this problem ever since it occurred (and it did occur, I'm positive on that) and now it works. I was prepared for exhausting session editing the whole image upload process.
Only thing I did, I added the image/pjpeg to validImage -function. I tried that last time I posted on this thread and it kept complaining that the images are too big (over 600 kB) even when the images were smaller than 200 kBs. Now I tried the image upload on IE with an image size of 520 kBs and it worked.
I'm still advising users not to use IE for uploading images and would like your input on this situation. I've been scouring the web to find someone else complaining about pjpeg-size issues but I haven't found anyone.
Jatar-K had some problem that he/she thought could be caused by the pjpeg-size. I'd like to hear if this was the case.
[edited by: deMorte at 11:51 am (utc) on Sep. 27, 2007]