2

I'm building my own simple CMS. Here is a problem with images. Loading large size images slow down the website. I'm here to ask how to resize an image to multiple dimensions for example: image.jpg orginal size is 1280x720pixels; for thumbnail to create image250x250.jpg; inside post usage image500x350.jpg and so on. Currently using the same image for thumbnails, posts and so on. I'm just styling with CSS.

Thanks and best regards!

Bleron
  • 57
  • 5

1 Answers1

0

After a user uploads an image, you'll need to create and retain multiple copies of that image on your server (one copy per desired size). The ImageMagick software is commonly used for such tasks.

There are many explanations online that will go into more detail, but in general you'll want to install ImageMagick on your server, then enable the ImageMagick PHP extension.

After creating a few copies of the uploaded image, you can use the Imagick::resizeImage function to independently modify the size of each one.

If you're unable to install the PHP extension, then you can instead invoke ImageMagick's convert command line utility via PHP's exec() function.

Nate
  • 1,442
  • 14
  • 22