PHP implements a general method for downloading images
Release: 2016-07-25 08:45:27
Original
1134 people have browsed it
- function getPicture($url,$pictureName){
- if ($url == "") return false;
- //Get the extension of the picture
- $info = getimagesize($url);
- $mime = $ info['mime'];
- $type = substr(strrchr($mime,'/'), 1);
- //Choose different image generation and saving functions for different image types
- switch($type){
- case 'jpeg':
- $img_create_func = 'imagecreatefromjpeg';
- $img_save_func = 'imagejpeg';
- $new_img_ext = 'jpg';
- break;
- case 'png':
- $img_create_func = 'imagecreatefrompng';
- $img_save_func = ' imagepng';
- $new_img_ext = 'png';
- break;
- case 'bmp':
- $img_create_func = 'imagecreatefrombmp';
- $img_save_func = 'imagebmp';
- $new_img_ext = 'bmp';
- break;
- case ' gif':
- $img_create_func = 'imagecreatefromgif';
- $img_save_func = 'imagegif';
- $new_img_ext = 'gif';
- break;
- case 'vnd.wap.wbmp':
- $img_create_func = 'imagecreatefromwbmp';
- $ img_save_func = 'imagewbmp';
- $new_img_ext = 'bmp';
- break;
- case 'xbm':
- $img_create_func = 'imagecreatefromxbm';
- $img_save_func = 'imagexbm';
- $new_img_ext = 'xbm';
- break;
- default:
- $img_create_func = 'imagecreatefromjpeg';
- $img_save_func = 'imagejpeg';
- $new_img_ext = 'jpg';
- }
- if ($pictureName == ""){
- $pictureName = time().". {$new_img_ext}";
- }else{
- $pictureName = $pictureName.".{$new_img_ext}";
- }
- $src_im = $img_create_func($url); //Create a new picture from url
- $img_save_func($ src_im, $pictureName); //Output file to file
- return $pictureName;
- }
Copy code
|
Download image, PHP
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
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31