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

php gets network pictures to display in the browser

WBOY
Release: 2016-07-25 08:51:35
Original
1722 people have browsed it
  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中的网页转换为图片,缩放后再显示到浏览器。



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template