Forum Moderators: coopster
I am uploading JPEG's, resizing them, and saving them to the server. My client was testing it when he uploaded a JPEG which resulted in a re-sized file with weird color changes. Blues were darker, oranges were darker, but white was the same, as well as black. The JPEG quality is set to 100.
While trying to debug this, I finally just passed the image through imagecreatefromjpeg() straight to imagejpeg() using imagecreatetruecolor() and it did the same thing:
# Content type was set above
$img = imagecreatefromjpeg("...");$new_height = round(((260 * $height) / $width),0);
$new_img = imagecreatetruecolor(260,$new_height);imagejpeg($new_img,"",100);
# Clear allocated memory on server
imagedestroy($new_img);
imagedestroy($img);
I even tried copying the pallet from the uploaded image to the new one, with no luck.
Here is the original code:
$filename = "uploads/images/" . $newID . "_ti.jpg";
$uploaded = move_uploaded_file($_FILES["TIfile"]["tmp_name"],$filename);if (($_FILES["TIfile"]["type"]!= "image/pjpeg") && ($_FILES["TIfile"]["type"]!= "image/jpeg")) {
$errmsg = urlencode($_GLOBALS["msgs"]["mime_not_jpg"]);
header("Location: ...");
exit;
}$imagehw = getimagesize($filename);
$width = $imagehw[0];
$height = $imagehw[1];if ($width >= 260) {
$img = imagecreatefromjpeg($filename);$new_height = round(((260 * $height) / $width),0);
$new_img = imagecreatetruecolor(260,$new_height);
imagecopyresampled($new_img,$img,0,0,0,0,260,$new_height,$width,$height);# Save file to server
imagejpeg($new_img,$filename,100);# Clear allocated memory on server
imagedestroy($new_img);
imagedestroy($img);
}
unlink("uploads/images/" . $iid . "_ti.jpg");
chmod($filename,0777);
<?php
function miniature($pict, $dest_pict){
$handle = @imagecreatefromjpeg($pict);
$x=imagesx($handle);
$y=imagesy($handle);
if($x > $y){
$max = $x;
$min = $y;
}
if($x <= $y){
$max = $y;
$min = $x;
}
//$size_in_pixel : Size max of the label in pixel. The size of the picture being
//proportional to the original, this value define maximum size
//of largest side with dimensions of the picture. Sorry for my english!
//Here $size_in_pixel = 100 for a thumbnail.
$size_in_pixel = '100';
$rate = $max/$size_in_pixel;
$final_x = $x/$rate;
$final_y = $y/$rate;
if($final_x > $x) {
$final_x = $x;
$final_y = $y;
}
$final_x = ceil($final_x);
$final_y = ceil($final_y);
$black_picture = imageCreatetruecolor($final_x,$final_y);
imagefill($black_picture,0,0,imagecolorallocate($black_picture, 255, 255, 255));
imagecopyresampled($black_picture, $handle, 0, 0, 0, 0,$final_x, $final_y, $x, $y);
if(!@imagejpeg($black_picture,$dest_pict.'/mini_'.$pict, $size_in_pixel))
imagestring($black_picture, 1, $final_x-4, $final_y-8, ".", imagecolorallocate($black_picture,0,0,0));
//The number is the quality of the result picture
imagejpeg($black_picture,'', '100');
imagedestroy($handle);
imagedestroy($black_picture);
}
/////// end make-mini function
include ('../../######'); // Connects to My DB
$getall="select * from minis";
$getall=mysql_query($getall);
while ($tt = mysql_fetch_assoc($getall)){
$pict = "$tt[num]".'.jpg';
$dest_pict = " ###mypath### /photomini";
miniature($pict, $dest_pict);
}
?>