High Performance Wordpress and Server - Part I - Server Setup
I have successfully managed to get around a 1 second load time on my Wordpress site, While getting 250 concurrent users over a 1 minute test period. (Source: https://webpagetest.org/result/210128_Di26_15d11aa18013d1df9ebc867e1aa9c2f3/) This was done with a combination of items, stemming from the server install up to Wordpress theme development. Here is how…Choosing NGINX for growth with Wordpress
Do it Because They Do WordPress.com is the cloud version of WordPress that is hosted and supported by Automattic.WordPress.com serves more than 33 million sites attracting over 339 million people and 3.4 billion pages each month. Since April 2008, WordPress.com has experienced about 4.4 times growth in page views. WordPress.com VIP hosts many popular…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…- 1
- 2
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!