StefanRSA Posted June 30, 2009 Share Posted June 30, 2009 I have script that is resizing images on the fly but in % values... How can I change this script to resize in pix rather than %? The Script: // Change the content type to jpeg header('Content-type: image/jpeg'); // Pull the variables from the query string $fileileSource = $_GET['imagesrc']; $percent = $_GET['percent'] / 100; $rotation = $_GET['rotation']; // Sizes of the image are stored in an array // index 0 is the width // index 1 is the height $size = getimagesize($fileileSource); $width = $size[0]; $height = $size[1]; $requiredWidth = $width * $percent; $requiredHeight = $height * $percent; // pull the image file in to a variable // for manipulation $thumbnailCanvas = imagecreatetruecolor($requiredWidth, $requiredHeight ); $originalCanvas = imagecreatefromjpeg($fileileSource); // Duplicate and resize (under the bonnet stuff) imagecopyresized($thumbnailCanvas, $originalCanvas, 0, 0, 0, 0, $requiredWidth, $requiredHeight, $width, $height); // Rotate the image by the desired degrees and set the created space to white $final = imagerotate($thumbnailCanvas, $rotation, 16777215); // Print the image imagejpeg($final); Link to comment https://forums.phpfreaks.com/topic/164257-how-to-change-to-pix-in-script/ Share on other sites More sharing options...
patrickmvi Posted June 30, 2009 Share Posted June 30, 2009 I'm not sure what the question is, if all you want to do is set the image to a specific pixel width and height then you would just not do all of those percentage calculations you're doing below. It would look more like this: // Change the content type to jpeg header('Content-type: image/jpeg'); // Pull the variables from the query string $fileileSource = $_GET['imagesrc']; $rotation = $_GET['rotation']; // Sizes of the image are stored in an array // index 0 is the width // index 1 is the height $size = getimagesize($fileileSource); $width = $size[0]; $height = $size[1]; $requiredWidth = $_GET['width']; $requiredHeight = $_GET['height']; // pull the image file in to a variable // for manipulation $thumbnailCanvas = imagecreatetruecolor($requiredWidth, $requiredHeight ); $originalCanvas = imagecreatefromjpeg($fileileSource); // Duplicate and resize (under the bonnet stuff) imagecopyresized($thumbnailCanvas, $originalCanvas, 0, 0, 0, 0, $requiredWidth, $requiredHeight, $width, $height); // Rotate the image by the desired degrees and set the created space to white $final = imagerotate($thumbnailCanvas, $rotation, 16777215); // Print the image imagejpeg($final); The $_POST['width'] and $_POST['height'] variables would contain the actual pixel values you want to pass. Link to comment https://forums.phpfreaks.com/topic/164257-how-to-change-to-pix-in-script/#findComment-866445 Share on other sites More sharing options...
StefanRSA Posted June 30, 2009 Author Share Posted June 30, 2009 That is basically what I wanted but am worried about the stretching of an image... I am not to sure how to make sure that If I set the width at 100px to keep it in the purportion it is suppose to be...? Link to comment https://forums.phpfreaks.com/topic/164257-how-to-change-to-pix-in-script/#findComment-866453 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.