Resizing the image in php for viewing purposes only

后端 未结 15 1724
面向向阳花
面向向阳花 2020-12-14 13:09

Okay, the reason I posted this is because I wasn\'t sure what to search for. I\'ll try to explain it as clearly as I can.

Say, I have an image sized 800x600. The box

15条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 13:36

     $ratio_orig) {
           $width = floor($height*$ratio_orig);
        } else {
           $height = floor($width/$ratio_orig);
        }
    
        // Resample
        $tempimg = imagecreatetruecolor($width, $height);
        imagecopyresampled($tempimg, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
        imagejpeg($tempimg, $thumbname, 80);
    }
    
    if (!function_exists('sys_get_temp_dir')) {
      function sys_get_temp_dir() {
        if (!empty($_ENV['TMP'])) { return realpath($_ENV['TMP']); }
        if (!empty($_ENV['TMPDIR'])) { return realpath( $_ENV['TMPDIR']); }
        if (!empty($_ENV['TEMP'])) { return realpath( $_ENV['TEMP']); }
        $tempfile=tempnam(uniqid(rand(),TRUE),'');
        if (file_exists($tempfile)) {
        unlink($tempfile);
        return realpath(dirname($tempfile));
        }
      }
    }
    ?>
    

    Save the file as imageresize.php and put this file in your image folder and just use the code like this to show image

    " />
    

    you can use this code to show images in different sizes.

提交回复
热议问题