

Some socks are longer than others and so you might have the image sizes ranging from 200×400 up to 600×750 pixels. But this doesn’t mean that you have to use the default image size each time, nor risk the quality of the image being degraded when it is stretched or crunched into a space. Well, you’re proud of these fantastic socks and want people to see as much of them as possible: on the product views page, on the search page, on the listing page, etc. Let’s say you have a great line of socks that you want to sell through your site. But I thought I could create a script that would do exactly what I wanted… Getting Started I am by no means a PHP guru - in fact, I taught myself the language sometime in the summer of 2002, so by most standards, I’m still a newbie. So, with the knowledge I’d gained using PHP almost on a daily basis, I sat down and started figuring out a function to achieve these goals. I wanted one script to do all of this dynamically.I wanted the size of the altered image to keep its aspect ratio, no matter whether it was landscape or portrait.But in this particular case, I wanted to be able to display various sizes of the same image, without having 4,000 different thumbnails sitting around taking up space. In most cases, I would use ImageMagik so that I could have a regular version and a thumbnail version of each image.

Why couldn’t I just use something like ImageMagik?
#Php resize image code
I thought to myself, “I don’t feel like having 4,000 different thumbnails on my server for each product, and I don’t want to have the image look all jacked-up and distorted if I hard code the image width and height in my HTML”. Recently, as I built a Website to show off a range of products, I realized that not only was I going to want to use the same product image over and over again, but I was going to want to use that same image at different sizes throughout the site! If you’re anything like me, you’re probably lazy (and if you’re not, give yourself a pat on the back!).
