when i create a thumnail from a jpeg the thumbnail created the color doesnt match or even come close how can i fix this
<?php
function thumbnail($i,$nw,$p,$nn) {
$image = getimagesize ($i);
$image_width = $image[0];
$image_height =$image[1];
$image_type = $image[2];
if ($image_type == 2) {
$img=imagecreatefromjpeg($i);
$scale=$nw/$image_width;
$nh=ceil($image_height*$scale);
$newimg=imagecreatetruecolor($nw,$nh);
imagecopyresized($newimg,$img,0,0,0,0,$nw,$nh,$image_width,$image_height);
imagejpeg($newimg, $p.$nn);
imagedestroy($img);
imagedestroy($newimg);
return true;