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
https://forums.phpfreaks.com/topic/74386-image-upload-woes/
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
https://forums.phpfreaks.com/topic/74386-image-upload-woes/#findComment-375840
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.