Reputation: 9293
I need to scale all images inside a folder (images323
);
all images have width smaller then 960px
they should have a new width - 960px
- and keep the quality
and aspect ratio
.
I'm getting error: - imagescale() expects parameter 1 to be resource, string given
$arr = glob('images323/*.jpg');
foreach($arr as $el){
imagescale($el, 960, -1); // error
}
Upvotes: 0
Views: 532
Reputation: 11622
This error indicates that you are passing a string to imagescale function, imagescale function require the first parameter to be a resource, which is a file handle
so you code should be like:
$arr = glob('images323/*.jpg');
foreach($arr as $el){
$handle = imagecreatefromjpeg($el);
imagescale($el, 960, -1); // error
}
Note that I'm using imagecreatefromjpeg because you are scanning for JPEG images, for PNG, use imagecreatefrompng
Upvotes: 1