-1

What is the best way to fit an image for thumbnail example 200px x 200px ?

after researching here are the best options I found:

  1. save 2 set of images for thumbnail and large slideshow purpose, for example if user uploads img001 , then save 2 copies of the same image one for thumbnail(resized 200px x 200px) and one for large slideshow purpose(actual dimension).

  2. just use one image and use it responsive with 100% width and 200px height(for thumbnail) and let the large image be itself.

with solution 2 I found that the thumbnail image always look shrunk.

Please give some suggestions on dealing with thumbnail images, thanks in advance

codec
  • 47
  • 1
  • 7

1 Answers1

0

Here is what i suggest.

Store only one original image at the time of saving. Maintain a Cache folder for your images in such a way that the cached images are created whenever you need to display on whatever size you want.

eg : make a function something like

getCachedImage($post->image, '200x200-','200','200')

and inside that function you can have some logic to save a precise sized image you want inside cache folder. Dont forget to check if the following size image is already been saved. You can use size as prefix ('200x200-$fileName') as i have mentioned on example. I use Image Intervention Package for my laravel project to save those picture in the size i want it to display.

Now you can call this function in your view wherever you need to display an image and you can call any size image you want.

You will always have shrunk image if you use your option number 2. And Even in your option 1, if you saved one extra image as thumbnail you will never have exact needed size for you thumbnail, so at some place this thumbnail is also gonna shrink.