Setup SVN With Attached Drives on CentOS
These are the step that I took to create a SVN server using CentOS 7, while attaching drives as repositories instead of creating a monstrous system drive and importing everything there. If you follow to a "T", you too can have the play-ground I have =) I will lay out…My KitKat Performance Tweaks
Been awhile since I've posted anything... holy moly has it!So, as I am sure most of you are aware, I am a programmer/developer by heart and soul, so it was only a matter of time before I started (finally) getting into doing some tweaking for Android devices. As a result,…Performance Tweaks for Big Wordpress Sites
Tip #1 We backed up the the wp_posts table and then used a simple MySQL command to remove old post revisions. This decreased the table size from 400MB to 120MB: DELETE FROM `wp_posts` WHERE post_type = 'revision' AND post_date NOT LIKE '2012-%' Long-term solution There are WordPress plugins which can…PHP Image Upload Resizer
Need a good way to resize your uploaded image? While keeping the height/width ratio? Why would you need to do this? Well, like most of you, I did not need to keep full sized images that I upload on page, and needed a good way to create thumbnails, and resize…Cookie Notice
This site utilizes cookies to improve your browsing experience, analyze the type of traffic we receive, and serve up proper content for you. If you wish to continue browsing, you must agree to allow us to set these cookies. If not, please visit another website.
PHP Image Upload Resizer
Need a good way to resize your uploaded image? While keeping the height/width ratio?
Why would you need to do this? Well, like most of you, I did not need to keep full sized images that I upload on page, and needed a good way to create thumbnails, and resize the originals down to a more manageable, more web friendly size.
This will do the trick… no words of caution, no instructions, just code… use it how you like 🙂
<?php function ResizeImage($inputFile, $filepath, $ext, $maxWidth, $maxHeight){ /* Get some details about the image */ $srcDetails = getimagesize($inputFile); switch ($srcDetails[2]) { case 1: //GIF $source_image = imagecreatefromgif($inputFile); break; case 2: //JPEG $source_image = imagecreatefromjpeg($inputFile); break; case 3: //PNG $source_image = imagecreatefrompng($inputFile); break; case 6: //WBMP $source_image = imagecreatefromwbmp($inputFile); break; default: break; } /* Original Dimensions */ $width = imagesx($source_image); $height = imagesy($source_image); // Target and original image ratio $target_ratio = $maxWidth / $maxHeight; $original_ratio = $width / $height; /* find the "desired height" of this thumbnail, relative to the desired width, and vice-versa */ if(($maxWidth <= $width) || $maxHeight <= $height){ if($target_ratio == $original_ratio){ // ratio's are equal, no need to calculate $desired_height = $maxHeight; $desired_width = $maxWidth; }elseif($target_ratio > $original_ratio){ // need to get the proper width $desired_height = $maxHeight; $desired_width = $width * ($maxHeight / $height); }elseif($target_ratio < $original_ratio){ // need to get the proper height $desired_height = $height * ($maxWidth / $width); $desired_width = $maxWidth; } }else{ $desired_height = $maxHeight; $desired_width = $maxWidth; } $virtual_image = imagecreatetruecolor($desired_width, $desired_height); imagecopyresized($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height); /* create the physical thumbnail image to its destination */ switch ($srcDetails[2]) { case 1: //GIF imagegif($virtual_image, $filepath); imagedestroy($virtual_image); break; case 2: //JPEG imagejpeg($virtual_image, $filepath, 100); imagedestroy($virtual_image); break; case 3: //PNG imagepng($virtual_image, $filepath, 6); imagedestroy($virtual_image); break; case 6: //WBMP imagewbmp($virtual_image, $filepath); imagedestroy($virtual_image); break; default: // Don't do anything because it's not an image imagedestroy($virtual_image); break; } } ?>
Enjoy, and as always…
Happy Coding!