0

I would like to resize an image in URL such as localhost/changimage.php?percent=40. I have already resized it in php. But user should resize it by typing in URL here is my PHP code: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);

 ?>

I have no idea how to do it in URL.

2
  • 4
    Not sure i understood your question right, but try $percent = $_GET['percent']; Commented Mar 26, 2013 at 8:02
  • 1
    @Nerfair $percent = array_key_exists('percent', $_GET) ? $_GET['percent']:0; is slightly better : Commented Mar 26, 2013 at 8:06

3 Answers 3

1

OR

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

To check if percent has a value

Sign up to request clarification or add additional context in comments.

Comments

1

Try it.

$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);

Comments

0

maybe something like that:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.