在php中调整照片大小

时间:2014-04-07 19:12:20

标签: php resize

这是以下示例中提供的代码:http://www.php.net/manual/en/function.imagecopyresampled.php

test.jpg尺寸:500x357

phpdotnet_resize.php

这显示test.jpg调整为200x142

    <?php
            // The file
            $filename = 'test.jpg';

            // Set a maximum height and width
            $width = 200;
            $height = 200;

            // Content type
            header('Content-Type: image/jpeg');

            // Get new dimensions
            list($width_orig, $height_orig) = getimagesize($filename);

            $ratio_orig = $width_orig/$height_orig;

            if ($width/$height > $ratio_orig) {
               $width = $height*$ratio_orig;
            } else {
               $height = $width/$ratio_orig;
            }

            // Resample
            $image_p = imagecreatetruecolor($width, $height);
            $image = imagecreatefromjpeg($filename);
            imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

            // Output
            imagejpeg($image_p, null, 100);

 echo "<img src='$filename'>";

    ?>

但是,这会将test.jpg显示为原始大小500x357

 <?php
       include "phpdotnet_resize.php";
                echo "<img src='$filename'>";
?>

我正在尝试将已调整大小的test.jpg移动到images /但它会继续移动原始大小的图像。

upload.php(仅显示相关摘录)

  include "phpdotnet_resize.php";
  if(move_uploaded_file($file_tmp,"images/".$filename)){
        echo "Success";

0 个答案:

没有答案