Php obtains the image address in the CSS file, downloads it, and saves it to the local device. Copy the code as follows: *** get the image address in CSS and save it to the local * classgetInCssImage {*** save the image * @ param $ cssUrlcss url * @ param $ dir save
The code is as follows: |
|
/** * Obtain the image address in CSS and save it to the local device. */ Class getInCssImage { /** * Save the image * @ Param $ css url * @ Param $ dir: Directory for saving images * @ Return void */ Static public function saveImage ($ cssUrl, $ dir) { $ Content = file_get_contents ($ cssUrl ); $ Patterns = '/images (. *). (jpg | gif | png)/'; // the regular expression needs to be changed based on different addresses. Preg_match_all ($ patterns, $ content, $ matches ); $ ImagesUrls = $ matches [0]; If (! Is_dir ($ dir )) Mkdir (dirname (_ FILE _). '/'. $ dir, 0777 ); Foreach ($ imagesUrls as $ image) { Ob_start (); $ ImageUrl = "http://www.xx.com/". $ image; // This address was originally obtained by a program. Slack Readfile ($ imageUrl ); $ Img = ob_get_contents (); Ob_end_clean (); $ Size = strlen ($ img ); $ LocalImage = $ dir. strchr ($ image, '/'); // The image address saved locally. $ Fp = fopen ($ localImage, 'A '); Fwrite ($ fp, $ img ); Fclose ($ fp ); } } } }
$ Content = getInCssImage: saveImage ('/css/css.css', 'image '); |
WaterMark/*** get the image address in CSS, and save it to the local */class getInCssImage {/*** Image save down * @ param $ cssUrl css url address * @ param $ dir save...