Phpgd library for remote image download
- /**
- * Remote Image Download
- * By bbs.it-home.org
- */
- Header ("Content-type: text/html; charset = utf-8 ");
-
- If (! Empty ($ _ POST ['submit ']) {
- $ Url = $ _ POST ['URL'];
- $ PictureName = $ _ POST ['picturename'];
- $ Img = getPicture ($ url, $ pictureName );
- Echo'';
- }
- Function getPicture ($ url, $ pictureName ){
- If ($ url = "") return false;
- // Obtain the image extension
- $ Info = getimagesize ($ url );
- $ Mime = $ info ['Mime '];
- $ Type = substr (strrchr ($ mime, '/'), 1 );
- // Select different image generation and storage 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 image from the url
- $ Img_save_func ($ src_im, $ pictureName); // output the file to the file
- Return $ pictureName;
- }
- ?>
2. webpage content
The running result is as follows: (The image is automatically saved in the current file directory) |