kvnmck18 Posted December 1, 2006 Share Posted December 1, 2006 I know this is a "security risk" of sorts... but any ideas on making a PHP image uploader (for PHP 4); when image is uploaded it limits the image to a max height and width (while still keeping it in proportion to it's original dimensions) and also created a second image that is the same image just scalled down more to a smaller max height & width dimension (to be used as a thumbnail).I'm currently look at imagecreatefrompng() and imagecreatefromjpg() funtions, along with php upload functions, imagecopyresized().Sugguestions? Any previous codes floating around that I can work with?Thanks~ Link to comment Share on other sites More sharing options...
justsomeguy Posted December 1, 2006 Share Posted December 1, 2006 You will want to use imagecopyresampled instead of imagecopyresized. I have a gallery I made that does all of that I can post, but it saves in a database instead of files. I can post it if you want. Link to comment Share on other sites More sharing options...
kvnmck18 Posted December 1, 2006 Author Share Posted December 1, 2006 I have this so far as a starter this will work for making a thumbail 50% smaller: <?php$filename = 'image.jpg';$percent = 0.5;header('Content-type: image/jpeg');list($width, $height) = getimagesize($filename);$newwidth = $width * $percent;$newheight = $height * $percent;$thumb = imagecreatetruecolor($newwidth, $newheight);$source = imagecreatefromjpeg($filename);imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);imagejpeg($thumb);?> This helps in sorts but instead of a percent I want it to be like "$height < 50px"...to set a max height then get the ratio of what the difference is and make the width be in proportion.Aren't they similar? Send it... let me try it. Link to comment Share on other sites More sharing options...
justsomeguy Posted December 1, 2006 Share Posted December 1, 2006 Here is the complete code:http://www.manchine.net/steve/files/gallery.zipThis was sort of an experimental project for me, so there are a few things I do that I normally wouldn't. The entire thing is all in the index.php file (except for some includes), and it saves pictures in the database. You can execute the create_db.php file to set up the database after you modify the db_con.php file. The setup and usage instructions are in the index.php file. There are a few variables to edit in index.php as well. You will probably be interested in the add_image function inside functions.php.Let me know if you have questions. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now