基本的图片保存类,对于gif图片,可进行静态化处理<?php <br />
/**<br>
* Author 米国村长<br>
* @param $url 抓取图片的地址<br>
* @param $filepath 图片保存路径<br>
* @param $pre 图片保存名称前缀,可设置为循环递增或者随机数,减小重名几率*/<br>
<br>
class getImage{<br>
public function getImage($url,$filepath,$pre) {<br>
if ($url == "") {<br>
return false;<br>
}<br>
$arr = explode('.',$url);<br>
$ext = end($arr);<br>
$uniq = uniqid(); //设置一个唯一id<br>
<br>
/*对gif图片进行静态化,可用作缩略图*/<br>
if($ext == "gif"){ //判断是否为gif。若是,则进行静态化处理<br>
$gif_flag = 1; //设置图片为gif的标记为1<br>
$new_ext = 'jpg'; <br>
if(!is_file($filepath)) mkdir($filepath,0777);//建立文件夹<br>
$name = $filepath.'/'.$pre.$uniq; //文件的保存路径名称(无后缀)<br>
$name_jpg = $name.'.'.$new_ext; //jpg的保存路径名称<br>
$name_gif = $name.'.gif'; //gif的保存路径名称<br>
<br>
$img = file_get_contents($url); //抓取内容<br>
$this->mkFile($name_jpg,$img); //创建jpg文件<br>
$this->mkFile($name_gif,$img); //创建gif文件<br>
return array($name_gif,$name_jpg,$gif_flag)); //返回图片路径+名称+标记<br>
<br>
}else{ //不是gif图片则直接保存本地<br>
<br>
$gif_flag = 0; //设置gif标记为0<br>
if(!is_file($filepath)) mkdir($filepath,0777);<br>
$name = $filepath.'/'.$pre.$uniq.$ext; //图像保存的名称和路径<br>
$img = file_get_contents($url); //抓取内容<br>
$this->mkFile($name,$img);<br>
return array($name,'',$gif_flag); //返回图片路径+名称<br>
}<br>
}<br>
<br>
private function mkFile($name,$content){<br>
if(!is_file($name)) mkdir($name,0777); //创建文件<br>
file_put_contents($name,$content) //填充文件<br>
}<br>
}<br>
?>
AD:真正免费,域名+虚机+企业邮箱=0元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
