Home >Backend Development >PHP Tutorial >php gets network pictures to display in the browser

php gets network pictures to display in the browser

WBOY
WBOYOriginal
2016-07-25 08:51:351720browse
  1. Get Image From Web
复制代码

2、文件 getimage.php

  1. // set up variable
  2. $url = $_REQUEST['url'];
  3. // echo "

    8 ".$url."

    ";
  4. $ext = substr($url, strrpos($url, '.')+1);
  5. // echo '

    9 '.$ext.'

    ';
  6. $filename = substr($url, strrpos($url, '/')+1, -(strlen($ext) + 1));
  7. // echo '

    10 '.$filename.'

    ';
  8. if ($ext == 'jpg') {
  9. $im = imagecreatefromjpeg($url);
  10. if ($im) {
  11. // echo '

    created image handle

    ';
  12. $width = imagesx($im);
  13. $height = imagesy($im);
  14. $x = $width/2;
  15. $y = $height/2;
  16. $dst = imagecreatetruecolor($x, $y);
  17. imagecopyresampled($dst, $im, 0, 0, 0, 0, $x, $y, $width, $height);
  18. header("Content-Type:image/jpeg");
  19. // imagejpeg($dst, 'imgdst.jpg');
  20. imagejpeg($dst);
  21. imagedestroy($dst);
  22. imagedestroy($im);
  23. // echo '';
  24. }
  25. }
  26. ?>
复制代码

说明: 将收到的url中的网页转换为图片,缩放后再显示到浏览器。



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn