0

我想调整 URL 中的图像大小,例如localhost/changimage.php?percent=40. 我已经在 php.ini 中调整了它的大小。但是用户应该通过输入 URL 来调整它的大小,这是我的 PHP 代码:changimage.php

<?php

 $filename = '/var/www/html/zahir/images/bike.jpeg';

  $percent = 0.5; 

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

    list($width, $height) = getimagesize($filename);

     $new_width = $width * $percent;

       $new_height = $height * $percent;

         $image_p = imagecreatetruecolor($new_width, $new_height);

  $image = imagecreatefromjpeg($filename)
;
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

  imagejpeg($image_p, null, 100);

 ?>

我不知道如何在 URL 中做到这一点。

4

3 回答 3

1

试试看。

$percent = 0;
   if (isset($_GET["percent"])) {
       $percent = ($_GET["percent"] / 100);
      }
    if ($percent <= 0) {
        $percent = 1;
    }

    $filename = '/home/deepakgupta/Pictures/phone.jpg';

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

    list($width, $height) = getimagesize($filename);

    $new_width = $width * $percent;

    $new_height = $height * $percent;

    $image_p = imagecreatetruecolor($new_width, $new_height);

    $image = imagecreatefromjpeg($filename)
    ;
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

    imagejpeg($image_p, null, 100);
于 2013-03-26T08:27:13.930 回答
1

或者

$percent = 0.5;
if (isset($_GET['percent'])) {$percent = $_GET['percent']/100;}

检查百分比是否有值

于 2013-03-26T08:42:36.580 回答
0

也许是这样的:

$percent = 0.5;
if ($_GET['percent']) {$percent = $_GET['percent']/100;}
于 2013-03-26T08:26:11.317 回答