Resize image using php?

Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
Hi, perhaps the question will seem stupid, but as I'm new, I don't know what I'm doing wrong, so please help.

The problem is this: For example, the image exceeds the size and I need to bring it to the maximum allowed size, which is recorded in the variables $width and $height.
If the image exceeds the dimensions, but it is horizontal all working as intended. If the image is vertical, it is not given to the maximum allowed value, which is recorded in the variable height. What am I doing wrong? Maybe there's some more elegant method of bringing the image to the maximum allowed size?

PS I need to do it php, a js

//the code causes the picture to maximum set sizes

header('Content-Type: image/jpeg');
$filename = 'imagev.jpg';
$width = 300; //maximum values
$height = 300;

list($width_orig, $height_orig) = also, ($filename);// prisvoeniem the values of the variables width and height of the original

if ($width_orig > $width) {
$w_ratio = $width / $width_orig;
$fin_hegight = $height_orig * $w_ratio;
$fin_width = $width;
} elseif ($height_orig > $height){
$h_ratio = $height / $height_orig;
$fin_width = $width_orig * $h_ratio;
$fin_height = $height;

$image_p = imagecreatetruecolor($fin_width, $fin_hegight);
$image = imagecreatefromjpeg($filename);

imagecopyresampled($image_p, $image, 0, 0, 0, 0, $fin_width, $fin_hegight, $width_orig, $height_orig);

imagejpeg($image_p, null, 100);
by | 27 views

1 Answer

0 like 0 dislike

Related questions

0 like 0 dislike
3 answers
0 like 0 dislike
3 answers
asked Apr 4, 2019 by Stairdeck
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Jun 11, 2019 by zakharkang
110,608 questions
257,186 answers
35,647 users