spikypunker Posted April 14, 2010 Share Posted April 14, 2010 Hey guys Need some help using ImageMagick, does anyone know how to do a simple resize? All i need it to do is upload an image and then resize to a set value and saved to a users folder. I'll work out how to get it to the users folder and take in the dynamic sizes using simple php, but i just need some help on implementing the ImageMagick calls, does anyone have any experience in this server tech? I've trawled the support for it and am having real troubles understanding it! So far i've got the image uploader and i just need to know how to add into this a line that calls ImageMagick and resizes, before saving? Here's what i got so far: <?php $user = $_GET['user']; if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) { $filename = basename($_FILES['uploaded_file']['name']); $ext = substr($filename, strrpos($filename, '.') + 1); if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") && ($_FILES["uploaded_file"]["size"] < 100000000)) { $newname = dirname(__FILE__).'/images/'.$filename; if (!file_exists($newname)) { if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) { echo "<meta http-equiv=\"refresh\" content=\"0;URL=profile.php?user=$user\">"; } else { echo "Error: A problem occurred during file upload!"; } } else { echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists"; } } else { echo "Error: Only .jpg images under 350Kb are accepted for upload"; } } else { echo "Error: No file uploaded"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/198496-resizing-help-using-imagemagick/ Share on other sites More sharing options...
fivestringsurf Posted April 14, 2010 Share Posted April 14, 2010 here's a snippet i yanked from one of my past projects...you should be able to integrate it: $imagename = $_FILES['new_image']['name']; $source = $_FILES['new_image']['tmp_name']; $target = "images/".$imagename; move_uploaded_file($source, $target); $imagepath = $imagename; $save = "images/" . $imagepath; //This is the new file you saving $file = "images/" . $imagepath; //This is the original file list($width, $height) = getimagesize($file) ; $modwidth = 300; $diff = $width / $modwidth; $modheight = $height / $diff; $tn = imagecreatetruecolor($modwidth, $modheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; $save = "images/sml_" . $imagepath; //This is the new file you saving $file = "images/" . $imagepath; //This is the original file list($width, $height) = getimagesize($file) ; $modwidth = 80; $diff = $width / $modwidth; $modheight = $height / $diff; $tn = imagecreatetruecolor($modwidth, $modheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; Quote Link to comment https://forums.phpfreaks.com/topic/198496-resizing-help-using-imagemagick/#findComment-1041994 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.