php在url中读写图像

php在url中读写图像,php,Php,我想在URL中调整图像的大小,例如localhost/changimage.php?percent=40。我已经用php调整了它的大小。但用户应该通过键入URL来调整其大小 这是我的PHP代码:changimage.PHP <?php $filename = '/var/www/html/zahir/images/bike.jpeg'; $percent = 0.5; header('Content-type: image/jpeg'); list($width

我想在URL中调整图像的大小,例如
localhost/changimage.php?percent=40
。我已经用php调整了它的大小。但用户应该通过键入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中执行此操作。

可能类似于:

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

$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);
$percent=0;
如果(isset($_GET[“percent”])){
$percent=($_GET[“percent”]/100);
}
如果($百分比或


要检查百分比是否有值,我不确定我是否正确理解了您的问题,请尝试$percent=$\u GET['percent'];@Nerfair
$percent=array\u key\u存在('percent',$\u GET)?$\u GET['percent']:0;
稍好一些:
$percent = 0.5;
if (isset($_GET['percent'])) {$percent = $_GET['percent']/100;}