php - 使用 php 调整 url 上的图像大小
问题描述
我有一个存储在网络服务器中的图像。例如 https://victorthemes.com/themes/glazov/wp-content/uploads/2017/10/p-sidebar-two.jpg
现在我想用 php 调整该图像的大小。
我找到了这段代码,但它太旧了,不能与 php 7.2 一起使用
<?php
$remote_file = 'https://victorthemes.com/themes/glazov/wp-content/uploads/2017/10/p-sidebar-two.jpg';
$new_width = 342;
$new_height = 268;
list($width, $height) = getimagesize($remote_file);
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($remote_file);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
header('Content-Type: image/jpeg');
imagejpeg($image_p, NULL, 100);
imagedestroy($image_p);
?>