note 62935 added to function.imagejpeg
| From: | Yirtne at osu1 dot php dot net | Date: | Sun, 12 Mar 2006 21:04:08 +0000 |
| Subject: | note 62935 added to function.imagejpeg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-105385@lists.php.net to get a copy of this message | ||
I'm experiencing weird behaviour with imagejpeg() function.
I'm trying to upload a jpg image with a form, check wether it does not exceed 600px width, and
store it in a mysql database:
<?php
// Get rid of magic_quotes
function getsafe($tmp) {
if (!get_magic_quotes_gpc()) return $tmp;
else return stripslashes($tmp);
}
// Read the image
$file = imagecreatefromjpeg($_FILES['file']['tmp_name']);
// Resize and write to temporary file
$sizex = imagesx($file);
$sizey = imagesy($file);
if ($sizex > 600) {
$newsizex = 600;
$newsizey = 600*$sizey/$sizex;
$img = imagecreatetruecolor($newsizex, $newsizey);
imagecopyresampled($img, $file, 0, 0, 0, 0, $newsizex, $newsizey, $sizex, $sizey);
imagejpeg($img, $PATH_TEMPIMG);
} else imagejpeg($file, $PATH_TEMPIMG);
// Store in mysql database
$safeimg = "'".mysql_real_escape_string(getsafe(fread(fopen($PATH_TEMPIMG,
"r"), $_FILES['file']['size'])))."'";
mysql_query("INSERT INTO test (image) VALUES (".$safeimg.")") or
die(mysql_error());
?>
the problem is that imagejpeg() sometimes (not always!) corrupts the picture. It still shows, but
presents weird artifacts and wrong colours.
please note that it does not happen always: different compression ratios for different pictures may
make it show correctly or not.
the server has magic_quotes on (can't change that, I'm not serveradmin) but my function
getsafe() should get rid of that problem.
has anybody experienced something similar before? any suggestions?
----
Server IP: 213.92.11.19
Probable Submitter: 151.47.133.40
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.imagejpeg.php
Edit -- http://master.php.net/note/edit/62935
Del: integrated -- http://master.php.net/note/delete/62935/integrated
Del: useless -- http://master.php.net/note/delete/62935/useless
Del: bad code -- http://master.php.net/note/delete/62935/bad+code
Del: spam -- http://master.php.net/note/delete/62935/spam
Del: non-english -- http://master.php.net/note/delete/62935/non-english
Del: in docs -- http://master.php.net/note/delete/62935/in+docs
Del: other reasons-- http://master.php.net/note/delete/62935
Reject -- http://master.php.net/note/reject/62935
Search -- http://master.php.net/manage/user-notes.php