There is a file in stored in the server, which for instance has dimension of 400 X 600 pixels. But in different part of the websites, we need the same picture of different dimension. For thumbnail, we usually need 50 X 50 pixels and if we choose to download the same picture with original dimension, it would take longer and the page load would slow down. If that picture is resized its size would go much more down (like, 500 KB to 50 KB). So, what I want is, before the browser downloads the picture, server should resize the picture to the dimensions as required in PHP script.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
You need to put the code in thumbnail code in a new file lets say image.php and then use this script as the src of the img tag with parameters of image file name, width and height.
You need change the "DSC01088.jpg" to echo $_GET['img']; after proper validation.
Yes, of course!
Google for PHP image resize code samples
Then create a download script and call it with the parameters, like this:
The script will load the image, resize it to the provided width and height and optionally crop it, then echo with appropriate headers for download...
There are a lot of ways of doing this... Sometimes it is just better to use google prior to asking here at SE...
Yes, with the PHP GD2 extension. Here's a quick tutorial
Use GD Library to create thumbnails
firstly get list of all the images in folder
You'll need PHP's GD library, then take a look at this and this and then link a php file which resizes instead of the image itself.
Also note the suggestion of neeraj, so you may resize it while uploading to get better performance.
In case if your host lacks PHP GD - which is highly unlikely - you should take a look at this or this.