Ec (2); classGetImage {& nbsp; var $ source; var $ save_to; var $ quality; & nbsp; functiondownload ($ methodcurl) {& nbsp; $ info @ GetImageSize ($ this-& gt; source); & nbsp; script ec (2); script
Class GetImage {
Var $ source;
Var $ save_to;
Var $ quality;
Function download ($ method = 'curl '){
$ Info = @ GetImageSize ($ this-> source );
$ Mime = $ info ['mime '];
// What sort of image?
$ Type = substr (strrchr ($ mime, '/'), 1 );
Switch ($ type ){
Case 'jpeg ':
$ Image_create_func = 'imagecreatefromjpeg ';
$ Image_save_func = 'imagejpeg ';
$ New_image_ext = 'jpg ';
// Best Quality: 100
$ Quality = isSet ($ this-> quality )? $ This-& gt; quality: 100;
Break;
Case 'png ':
$ Image_create_func = 'imagecreatefrompng ';
$ Image_save_func = 'imagepng ';
$ New_image_ext = 'png ';
// Compression Level: from 0 (no compression) to 9
$ Quality = isSet ($ this-> quality )? $ This-> quality: 0;
Break;
Case 'bmp ':
$ Image_create_func = 'imagecreatefrombmp ';
$ Image_save_func = 'imagebmp ';
$ New_image_ext = 'bmp ';
Break;
Case 'gif ':
$ Image_create_func = 'imagecreatefromgif ';
$ Image_save_func = 'imagegif ';
$ New_image_ext = 'gif ';
Break;
Case 'vnd. wap. wbmp ':
$ Image_create_func = 'imagecreatefromwbmp ';
$ Image_save_func = 'imagewbmp ';
$ New_image_ext = 'bmp ';
Break;
Case 'xbm ':
$ Image_create_func = 'imagecreatefromxbm ';
$ Image_save_func = 'imagexbm ';
$ New_image_ext = 'xbm ';
Break;
Default:
$ Image_create_func = 'imagecreatefromjpeg ';
$ Image_save_func = 'imagejpeg ';
$ New_image_ext = 'jpg ';
}
If (isSet ($ this-> set_extension )){
$ Ext = strrchr ($ this-> source ,".");
$ Strlen = strlen ($ ext );
$ New_name = basename (substr ($ this-> source, 0,-$ strlen). '.'. $ new_image_ext;
} Else {
$ New_name = basename ($ this-> source );
}
$ Save_to = $ this-> save_to. "/blog_insert_temp _". time (). mt_rand (1, 99). ".". $ new_image_ext;
// The output object is the same as the $ _ FILE variable, and the output object is the same as the normal Image Upload process.
$ Img_info ['name'] = basename ($ this-> source );
$ Img_info ['type'] = $ mime;
$ Img_info ['SIZE'] = 1000;
$ Img_info ['tmp _ name'] = $ save_to;
$ Img_info ['error'] = 0;
If ($ method = 'curl '){
$ Save_image = $ this-> LoadImageCURL ($ save_to );
} Elseif ($ method = 'gd '){
$ Img = $ image_create_func ($ this-> source );
If (isSet ($ quality )){
$ Save_image = $ image_save_func ($ img, $ save_to, $ quality );
} Else {
$ Save_image = $ image_save_func ($ img, $ save_to );
}
}
Return $ img_info;
}
Function LoadImageCURL ($ save_to ){
$ Ch = curl_init ($ this-> source );
$ Fp = fopen ($ save_to, "wb ");
// Set URL and other appropriate options
$ Options = array (CURLOPT_FILE => $ fp,
CURLOPT_HEADER => 0,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_TIMEOUT => 60); // 1 minute timeout (shocould be enough)
Curl_setopt_array ($ ch, $ options );
Curl_exec ($ ch );
Curl_close ($ ch );
Fclose ($ fp );
}
}