Jump to content

Please have a quick read. Your assistance is appreciated (Converting Images)


Modernvox

Recommended Posts

Hello Brothers,

 

I am reaching out for assistance with processing images(Mainly converting a users uploaded image to a thumbnail-deleting the original in the process)

 

Here is what I have wrote thus far, what shall I do to sucessfully complete the above?

 

<code>

<?php

 

$maxsize=28480;

$photo= $_FILES['photo'];           

    if (!is_uploaded_file($_FILES['photo']['tmp_name'])) {

                    $errorlist = "ERROR: <font color= \"red\">You must upload a file!</font>";

                   

                    }

 

        if ($_FILES['photo']['type'] != "image/gif" AND

            $_FILES['photo']['type'] != "image/pjpeg" AND

            $_FILES['photo']['type'] !="image/jpeg") {

            $errorlist = "ERROR: <font color= \"red\">You may only upload .gif or .jpeg files</font>";

       

            }

 

if ($_FILES['photo']['size']> $maxsize) {

$errorlist = "ERROR: <font color= \"red\">file must be less than $maxsize bytes.</font>";

unlink($_FILES['photo']['tmp_name']);

}

 

else {

move_uploaded_file($_FILES['photo']['tmp_name'], "./uploads/".$_FILES['photo']['name']);

print "<img src=\"./uploads/{$_FILES['photo']['name']}\" />";

 

echo "<b><font color= \"black\">Experience:</font></b>" . $exp. "</br>";

echo $influences . "<br/>";

echo $actual_location . "<br/><br/>";

echo $bio . "<br/>";

}

}

 

 

?>

 

</code>

This is part of a function that i got to resize a thumbnail

 

 

	$twidth = "100";   // Maximum Width For Thumbnail Images 
$theight = "75";   // Maximum Height For Thumbnail Images 
$lwidth = "400";   // Maximum Width For Thumbnail Images 
$lheight = "300";   // Maximum Height For Thumbnail Images

$picture = $_FILES['imagefile']['name'];   // Set $url To Equal The Filename For Later Use 

    if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") { 
        $imagename = $_FILES['imagefile']['name'];
	$source = $_FILES['imagefile']['tmp_name'];
	$target = "./users/".$_SESSION['username']."/albums/".$album."/".$imagename;
	move_uploaded_file($source, $target);

	$imagepath = $imagename;
	$save = "./users/".$_SESSION['username']."/albums/".$album."/full/" . $newname; //This is the new file you saving
	$file = "./users/".$_SESSION['username']."/albums/".$album."/" . $imagepath; //This is the original file

	$image = imagecreatefromjpeg($file) ; 

	$currwidth = imagesx($image);   // Current Image Width 
	$currheight = imagesy($image);   // Current Image Height 
	if ($currheight > $currwidth) {   // If Height Is Greater Than Width 
		$zoom = $lwidth / $currheight;   // Length Ratio For Width 
		$newheight = $lheight;   // Height Is Equal To Max Height 
		$newwidth = $currwidth * $zoom;   // Creates The New Width 
	} else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height) 
		$zoom = $lwidth / $currwidth;   // Length Ratio For Height 
		$newwidth = $lwidth;   // Width Is Equal To Max Width 
		$newheight = $currheight * $zoom;   // Creates The New Height 
	}

	$tn = imagecreatetruecolor($newwidth, $newheight) ; 
	imagecopyresampled($tn, $image, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight) ; 

	imagejpeg($tn, $save, 100) ; 

	imagedestroy($image);

	$save = "./users/".$_SESSION['username']."/albums/".$album."/thumbs/" . $newname; //This is the new file you saving
	$file = "./users/".$_SESSION['username']."/albums/".$album."/" . $imagepath; //This is the original file

	$image = imagecreatefromjpeg($file) ; 

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.