qadenza
qadenza

Reputation: 9293

imagescale to a new width and keep quality and aspect ratio

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

Answers (1)

ROOT
ROOT

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

Related Questions