How to adjust this script to use Glob instead of 1 file

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to adjust this script to use Glob instead of 1 file



I have created this script based on reading other posts on StackOverflow. The script creates a thumbnail from the original image and adds it to a folder. The source images are located on my local server so Glob would work however I am not sure how to adjust this script so that it will run this function on all files in a folder (Glob). I realize it may be memory intensive but I only need to do it a few times on several folders and I'll be done with it.



Just in case you are questioning the reason I have included $height2, it is a little hack I came up with where we create the thumbnail while maintaining the aspect ratio then only save the top 250px so that the thumb is 250 x 250 but not distorted (stretched). It works great.



I just need to adjust to do a batch of all images in the source folder.



Any help would be great. Please keep in mind that I am a front end developer (html and css) and not great at PHP. This script alone took me forever to make work lol.



If anyone can help me adjust it for a full folder, that would be great.



Thumbnail ("PathToFullSizeImages/.jpg", "OutputFolder/.jpg");
function Thumbnail($url, $filename, $width = 250, $height = true, $height2 = 250) {
$image = ImageCreateFromString(file_get_contents($url));
$height = $height === true ? (ImageSY($image) * $width / ImageSX($image)) : $height;
$output = ImageCreateTrueColor($width, $height2);
ImageCopyResampled($output, $image, 0, 0, 0, 0, $width, $height, ImageSX($image), ImageSY($image));
ImageJPEG($output, $filename, 100);


Thumbnail ("PathToFullSizeImages/.jpg", "OutputFolder/.jpg");
function Thumbnail($url, $filename, $width = 250, $height = true, $height2 = 250) {
$image = ImageCreateFromString(file_get_contents($url));
$height = $height === true ? (ImageSY($image) * $width / ImageSX($image)) : $height;
$output = ImageCreateTrueColor($width, $height2);
ImageCopyResampled($output, $image, 0, 0, 0, 0, $width, $height, ImageSX($image), ImageSY($image));
ImageJPEG($output, $filename, 100);





There are examples on php.net for the glob() function that you can consult php.net/manual/en/function.glob.php
– Funk Forty Niner
6 mins ago


glob()









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results