nightkarnation Posted August 13, 2010 Share Posted August 13, 2010 Hey guys! I have the following php code that grabs variables (and the browsed image) from Flash. //FLASH VARIABLES $Name = $_POST['Name']; $itemNumber = $_POST['itemNumber']; $filename = $_FILES['Filedata']['name']; $filetmpname = $_FILES['Filedata']['tmp_name']; $fileType = $_FILES["Filedata"]["type"]; $fileSizeMB = ($_FILES["Filedata"]["size"] / 1024 / 1000); list($filename, $extension) = explode('.', basename($_FILES['Filedata']['name'])); $filename = $Name; $target = $filename . $itemNumber . "." . $extension; // Place file on server, into the images folder move_uploaded_file($_FILES['Filedata']['tmp_name'], "images/".$target); This works perfect, but what I want to change is the width and height of the uploaded image. Any ideas/suggestions on how this could be done? Thanks in advance!! Cheers! Quote Link to comment Share on other sites More sharing options...
petroz Posted August 13, 2010 Share Posted August 13, 2010 There's a couple ways todo this... I believe the standard would be using the PHP GD library, but I found Imagick to be very very easy to use. Here is an example I used before... //upload image $target = 'pics/'.$event.'/'; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){ echo "0"; } else { echo "1"; } //create thumbnail $im = new Imagick('pics/'.$event.'/'.$_FILES['uploaded']['name']); $im->thumbnailImage(150,150); $im->writeImage($dir.'/thumb_'.$_FILES['uploaded']['name']); Quote Link to comment Share on other sites More sharing options...
nightkarnation Posted August 13, 2010 Author Share Posted August 13, 2010 Petroz thanks for you reply! I have been trying but I have no idea at all how to implement your script on mine. Any ideas anyone, please? Quote Link to comment Share on other sites More sharing options...
petroz Posted August 13, 2010 Share Posted August 13, 2010 First, check to see if imagick is install on your server with a php info. Once you get it installed its pretty simple. // Place file on server, into the images folder move_uploaded_file($_FILES['Filedata']['tmp_name'], "images/".$target); $im = new Imagick('$_FILES['Filedata']['tmp_name']); //open your file $im->thumbnailImage(150,150); //resize $im->writeImage($_FILES['Filedata']['tmp_name']); //write the thumbnail to the server Quote Link to comment Share on other sites More sharing options...
khalidmushtaq65 Posted August 13, 2010 Share Posted August 13, 2010 The way I did this... $data = $your_result_resource["image_field_from_table"]; $size = 50 $img = imagecreatefromstring($data); $width = imagesx($img); $height = imagesy($img); $aspect_ratio = $height/$width; if ($width <= $size) { $new_w = $width; $new_h = $height; } else { $new_w = $size; $new_h = abs($new_w * $aspect_ratio); } $new = imagecreatetruecolor($new_w,$new_h); imagecopyresampled($new,$img,0,0,0,0,$new_w,$new_h,$width,$height); header('Content-type: image/jpeg'); imagejpeg($new); imagedestroy($new); I hope it will work for you too.... Quote Link to comment Share on other sites More sharing options...
nightkarnation Posted August 13, 2010 Author Share Posted August 13, 2010 Awesome! Thanks a lot guys, very helpful! Cheers Quote Link to comment 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.