Code: Select all
function changeImagen($name, $image)
{
list($uploadedImgWidth, $uploadedImgHeight, $uploadedImgType) = getimagesize($image['tmp_name']);
if (substr(image_type_to_mime_type($uploadedImgType), 0, 5) != "image")
{
return "<script type='text/javascript'>alert("Unable to upload your image. File doesn't appear to be an image.");</script>";
}
$maxW = 150;
$maxH = 100;
$dimensionRatio = $uploadedImgWidth/$uploadedImgHeight;
if ($maxW/$maxH > $dimensionRatio)
{
$maxW = $maxH*$dimensionRatio;
}
else
{
$maxH = $maxW/$dimensionRatio;
}
$resizedImg = imagecreatetruecolor($maxW, $maxH);
$uploadedImg = imagecreatefromjpeg($eyecon['tmp_name']);
imagecopyresize($resizedImg, $uploadedImg, 0, 0, 0, 0, $maxW, maxH, $uploadedImgWidth, $uploadedImgHeight) or die("<script>alert('Failed at resizing!')</script>");
imagejpeg($resizedImg, "".$_SESSION['username']."/".$name.".jpg", 75) or die("<script>alert('Fialed at saving file!');</script>");
$connection = mysql_connect("IP", "username", "password") or die(msql_error());
$db = mysql_select_db("db", $connection) or die(mysql_error());
$results = mysql_query("UPDATE `table` SET `picture` = '$_SESSION[username]/$name.jpg' WHERE `username` = '$_SESSION[username]' AND `name` = '$name'") or die(mysql_error());
return "<script type='text/javascript'>alert('done');</script>";
}*sigh* Oh boy...
I'm using imagecreatetryecolor()?PHP.Net wrote:Note: There is a problem due to palette image limitations (255+1 colors). Resampling or filtering an image commonly needs more colors than 255, a kind of approximation is used to calculate the new resampled pixel and its color. With a palette image we try to allocate a new color, if that failed, we choose the closest (in theory) computed color. This is not always the closest visual color. That may produce a weird result, like blank (or visually blank) images. To skip this problem, please use a truecolor image as a destination image, such as one created by imagecreatetruecolor().