多个图像调整大小,具有相同的宽高比

时间:2013-03-25 16:02:30

标签: php javascript image resize image-resizing

如何调整具有相同宽高比的多个图像的大小。例如,

960x600 1152x720 1280×800 1440 1680×1050 1920×1200 2560×1600 2880x1800艺术 3840x2400

如果我们的图像尺寸为3840x2400,则这些像素具有相同的宽高比。我需要将3840x2400的图像大小调整为上面的像素。最好使用工具或PHP脚本或Javascript解决。

1 个答案:

答案 0 :(得分:1)

<?php
  $source = imagecreatefromjpeg("path_to_source/filename.jpg");
  $width = 960;
  $height = $width*(imagesy($source)/imagesx($source));
  $destination = imagecreatetruecolor($width, $height);
  imagecopyresampled($destination, $source, 0, 0, 0, 0, $width, $height, imagesx($source), imagesy($source));
  imagejpeg($destination,"path_to_destination/filename.jpg");
?>

更改$width其他尺码......

相关问题