php сжимаем изображения
<pre><?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$text = '/upload/articles/53066/1673596122_594V.jpg
/upload/articles/52994/1671542002_ZkJ7.jpg
/upload/articles/52928/1670425735_3049.jpg
/upload/articles/52928/1670425738_97P9.jpg
/upload/articles/52931/1670427197_BE52.jpg
/upload/articles/52928/1670425728_m3L7.jpg';
$text_webp = str_replace('.jpg', '.webp', $text);
$links = explode("\n", $text);
$links_webp = explode("\n", $text_webp);
// print_r($links_webp); exit();
$imagePath = $_SERVER['DOCUMENT_ROOT'].$links[0];
$sourceImage = imagecreatefromjpeg($imagePath);
//$sourceImage = imagecreatefrompng($imagePath);
if ($sourceImage) {
// Получаем ширину и высоту оригинального изображения
$originalWidth = imagesx($sourceImage);
$originalHeight = imagesy($sourceImage);
// Устанавливаем максимальную ширину
$maxWidth = 720;
$newWidth = $originalWidth;
$newHeight = $originalHeight;
if ($originalWidth > $maxWidth) {
$newWidth = $maxWidth;
$newHeight = round($originalHeight * $maxWidth / $originalWidth);
}
// Создаем новое изображение с измененным размером
$resizedImage = imagecreatetruecolor($newWidth, $newHeight);
// Копируем и изменяем размер оригинального изображения в новое
imagecopyresampled($resizedImage, $sourceImage, 0, 0, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight);
$outputPath = $_SERVER['DOCUMENT_ROOT'].$links_webp[0];
$quality = 80;
if (file_exists($outputPath))
unlink($outputPath);
imagewebp($resizedImage, $outputPath, $quality);
imagedestroy($sourceImage);
imagedestroy($resizedImage);
echo 'good '.$outputPath.'<br>';
} else {
echo 'NOT '.$outputPath.'<br>';
}