- function getPicture($url,$pictureName){
- if ($url == "") return false;
- //获取图片的扩展名
- $info = getimagesize($url);
- $mime = $info['mime'];
- $type = substr(strrchr($mime,'/'), 1);
- //不同的图片类型选择不同的图片生成和保存函数
- 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); //由url创建新图片
- $img_save_func($src_im, $pictureName); //输出文件到文件
- return $pictureName;
- }
复制代码
|
下載圖片, PHP
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
-
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