Jump to content

IMage upload woes


cooldude832

Recommended Posts

I'm trying to upload and resize an image, and for some reason its only copy part of the image

this is what i'm using

<?php
$img_types = array("image/jpg", "image/pjpg", "image/jpeg", "image/pjpeg", "image/png", "image/gif");
$new_path = ROOT."graphics/counselor/".$_SESSION['FacID'].".jpg";
if (in_array($_FILES['image']['type'], $img_types) && $to_q == 1){ 
if(copy ($_FILES['image']['tmp_name'], $new_path)){
    list($width, $height) = getimagesize($new_path);
	$target = 150;
	if ($width > $height) {
		$percentage = ($target / $width);
	}
	else {
		$percentage = ($target / $height);
	}
	//gets the new value and applies the percentage, then rounds the value
	$width = round($width * $percentage);
	$height = round($height * $percentage); 
	$imgdata = getimagesize($new_path);
	$thumb = ImageCreateTrueColor(150, 150);

	$source = imagecreatefromjpeg($new_path);
    imagecopyresized($thumb, $source, 0, 0, 0, 0, 150, 150, $width, $height);
	imagejpeg($thumb,$new_path,100);
	$q = "Update `".F_TABLE."` Set Image='1' Where FacID ='".$_SESSION['FacID']."'";
	$r = mysql_query($q) or die(mysql_error());
}
else{
	$errors[] = "The Image could not be uploaded please try again<br />".$_FILES['image']['tmp_name']."<br />".$new_path;
}
}
else{
if(!empty($_FILES['image']['tmp_name'])){
	$errors[] = "Invalid File Type must be a jpeg";
}
?>

Link to comment
Share on other sites

figured it out, but know its sorta a blur image any ideas?

<?php
if (in_array($_FILES['image']['type'], $img_types) && $to_q == 1){ 
if(copy ($_FILES['image']['tmp_name'], $new_path)){
    list($width, $height) = getimagesize($new_path);
	$target = 150;
	if ($width > $height) {
		$percentage = ($target / $width);
	}
	else {
		$percentage = ($target / $height);
	}
	//gets the new value and applies the percentage, then rounds the value
	$width1 = round($width * $percentage);
	$height1 = round($height * $percentage); 
	$imgdata = getimagesize($new_path);
	$thumb = ImageCreateTrueColor($width1, $height1);
	$source = imagecreatefromjpeg($new_path);
    imagecopyresized($thumb, $source, 0, 0, 0, 0, $width1, $height1, $width, $height);
	imagejpeg($thumb,$new_path,100);
	$q = "Update `".F_TABLE."` Set Image='1' Where FacID ='".$_SESSION['FacID']."'";
	$r = mysql_query($q) or die(mysql_error());
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.