Resize Image or Crop Image with Joe Lencioni’s Smart Image Resizer, WordPress Setup
Posted by Daniel - 9,107 Views
UPDATE: I just created a WordPress plugin called smartimageresizer to get an easy use of this Smart Image Resizer functionality into your WordPress post. Click here to check it.
__________________________
If you use WordPress and you are blogging about something which requires a personalized image for every post such as Gadget blogs or you want to use different images for every post you have for illustration purpose only like what we commonly found on the newspaper blogs, I think it’s a good idea to list the link to each post with an image attached to a particular post displayed along with the postname and if necessary with the excerpt on it.
Oh man, it’s hard to describe it with words but what I am trying to say is displaying the link to a post with a layout format as shown on the image at the leftside.
Okay, there is a problem displaying that kind of layout on your page if you don’t have images with the same size attached to each post you have. It won’t be big problem if you have the same ratio dimension on all of your images, resizing it with your CSS code will give the intended layout - it’s acceptable, even sometimes the hardcoded-resized image will get a little bit jagged, but if you have an image which has a different ratio dimension, the story will be different.
There is only one solution to solve the issue if you’re not intended to upload images with the same ratio dimension. The solution is to generate a new image with the new size. The logic is simple, resize it and if necessary, crop it.
How we’re going to do that? Of course with the help of phpGD library. Is there any function wrapper available to make the job easier? Yes! It’s called “Smart Image Resizer” created by Joe Lencioni.
But you have to know that it’s not a plugin, it’s basically a .php file so you need to do the setup manually. Based on the description at the comment section of the file, this .php file can be used to resizes images, intelligently sharpens, crops based on width:height ratios, color fills transparent GIFs and PNGs, and caches variations for optimal performance - just perfect to do the job, at least for me. This file requires PHP 5.1.0+ and GD installed.
SETTING UP THE FILE
- Download the image.php file from here.
- Extract the zipped file then place it on your /wp-content/uploads/ directory or something else you would like it to be.
- With the assumption that you place the image.php file on /wp-content/uploads/, create a folder called “imagecache” under /wp-content/uploads/.
- Make your “imagecache” directory writable by the web server (usually chmod 775).
- Done!
TESTING IT
- Put an image under your /wp-content/uploads/ directory. Pick the reasonably large one, for example 1024×768 so you can easily see the different between the original and the processed one.
- Rename it to raw.jpg or any other name.
- Open your browser then try these url combinations:
- /wp-content/uploads/image.php/processed.jpg?width=300?=/wp-content/uploads/raw.jpg
- /wp-content/uploads/image.php/processed.jpg?width=300&cropratio=1:1?=/wp-content/uploads/raw.jpg
- Go ahead and try with your own url combination.
The following images are the result of Joe Lencioni’s image.php file applied on an image of this blog. You can right click them to check the image properties.
![]() |
![]() |
| w=300 cropratio= none | w=200 cropratio=1:1 |
click here for the original image
If you done it correctly, you will see the processed image displayed on your browser. You can right click the image then select properties to check the attributes. You will see that the image location is the same with the url on the address bar of your browser. If something goes wrong, the error message will be displayed on the browser.
Let me know when you have problems setting up the file. You can either email me or put it on the comment section. I prefer the 2nd one though :)
Model: Joice Mewengkang - a friend.
UPDATE: I just created a plugin called smartimageresizer to get an easy use of this functionality. Click here to check it.
The following posts are programmatically considered as related to the current post by YARPP Plugin:
- SmartImageResizer Plugin, WordPress plugin based on Joe Lencioni’s Smart Image Resizer
- Resizing image on the fly with ASP.NET using the System.Drawing namespace
- ContuttoPDF (Wordpress Plugin to convert your Content to PDF)
- Wordpress, How to insert the Gravatar icon into the comment section
- Customizing the PDF file created with ContuttoPDF Wordpress Plugin
3 Responses to “Resize Image or Crop Image with Joe Lencioni’s Smart Image Resizer, WordPress Setup”
Leave a Reply
Hi, my name is Daniel Nugraha, a single male live on an island called Java, Indonesia. This is the place for me to share my interest in computer programming.
-
Get my Full Feed Here
Comments - Thanks Guys :)
Rangga Kusuma: Gan, Tengkiu buat postingan yang sangat berguna. Kebetulan ada project utk bikin sms gateway, dan converter Agan sangat berguna utk...
Chuck Norton: I actually went ahead & bolted over to Justin’s Get The Image plugin here: http://justintadlock.com/ar...
Chuck Norton: Question: is it possible to insert something like [custfieldimg=”joice1.jpg,15 0,1:1″] into the actual templates instead of...
Therese Lachance: Hi, Any idea how to have ContuttoPDF fetch the correct page language?
tresloukadu: yo how did u fixed when the tags shows <? and it shows < “& l t ; ” ?? please send me an email.
















March 3rd, 2009 at 9:56 pm
I get the following error msg:
Fatal error: Call to undefined function add_filter() in /home/myopenth/public_html/wp-content/uploads/image.php on line 12
I did exactly as U mentioned !
July 3rd, 2009 at 7:27 pm
[…] reading here: Resize Image or Crop Image with Joe Lencioni’s Smart Image Resizer, WordPress Setup | averagecoder Tags: plugins Comments0 Leave a Reply Click here to cancel […]
July 5th, 2009 at 9:23 pm
omfg, I’ve been looking for this for so long. BLESS YOUR HEART. Keep up the good work. I could just kiss you.