예제 #1
0
/**
* 测试
*/
function main()
{
    $url = 'http://www.nipic.com/';
    $handle = fopen($url, "r");
    if ($handle) {
        $content = stream_get_contents($handle, 1024 * 1024);
        $result = _filterUrl($content);
        //获取到图片的url
        //var_dump($result);
        foreach ($result as $key => $value) {
            $a = GrabImage($value);
            var_dump($a);
        }
    } else {
        return false;
    }
}
예제 #2
0
function makemobilethumb($url, $originname, $dir1, $dir2)
{
    global $_SGLOBAL, $_SC;
    //ÅжÏÎļþÊÇ·ñ´æÔÚ
    $srcfile = GrabImage($url, $originname, $dir1, $dir2);
    chdir(dirname(dirname(dirname(__FILE__))));
    //include_once('./data/data_setting.php');
    chdir($_SC['attachdir'] . $dir1 . '/' . $dir2);
    if (!file_exists($srcfile)) {
        return '';
    }
    //chdir('../../');
    $filename = basename($url);
    $dstpath = $srcfile;
    $dstthumbfile = $dstpath . '.thumb.jpg';
    //ËõÂÔͼ´óС
    $tow = 60;
    $toh = 60;
    $make_mobile = 1;
    $mobiletow = 400;
    $mobiletoh = 400;
    //»ñȡͼƬÐÅÏ¢
    $im = '';
    if ($data = getimagesize($srcfile)) {
        if ($data[2] == 1) {
            $make_mobile = 0;
            //make the picture fit for mobile device
            if (function_exists("imagecreatefromgif")) {
                $im = imagecreatefromgif($srcfile);
            }
        } elseif ($data[2] == 2) {
            if (function_exists("imagecreatefromjpeg")) {
                $im = imagecreatefromjpeg($srcfile);
            }
        } elseif ($data[2] == 3) {
            if (function_exists("imagecreatefrompng")) {
                $im = imagecreatefrompng($srcfile);
            }
        }
    }
    if (!$im) {
        return '';
    }
    $srcw = imagesx($im);
    $srch = imagesy($im);
    $towh = $tow / $toh;
    $srcwh = $srcw / $srch;
    if ($towh <= $srcwh) {
        $ftow = $tow;
        $ftoh = $ftow * ($srch / $srcw);
        $fmobiletow = $mobiletow;
        $fmobiletoh = $fmobiletow * ($srch / $srcw);
    } else {
        $ftoh = $toh;
        $ftow = $ftoh * ($srcw / $srch);
        $fmobiletoh = $mobiletoh;
        $fmobiletow = $fmobiletoh * ($srcw / $srch);
    }
    if ($srcw <= $mobiletow && $srch <= $mobiletoh) {
        $make_mobile = 0;
        //if the source picture is smaller than the size of mobile requested, then keep the origin.
    }
    if ($srcw > $tow || $srch > $toh) {
        if (function_exists("imagecreatetruecolor") && function_exists("imagecopyresampled") && @($ni = imagecreatetruecolor($ftow, $ftoh))) {
            imagecopyresampled($ni, $im, 0, 0, 0, 0, $ftow, $ftoh, $srcw, $srch);
            //´óͼƬ
            if ($make_mobile && @($mobileni = imagecreatetruecolor($fmobiletow, $fmobiletoh))) {
                imagecopyresampled($mobileni, $im, 0, 0, 0, 0, $fmobiletow, $fmobiletoh, $srcw, $srch);
            }
        } elseif (function_exists("imagecreate") && function_exists("imagecopyresized") && @($ni = imagecreate($ftow, $ftoh))) {
            imagecopyresized($ni, $im, 0, 0, 0, 0, $ftow, $ftoh, $srcw, $srch);
            //´óͼƬ
            if ($make_mobile && @($mobileni = imagecreate($fmobiletow, $fmobiletoh))) {
                imagecopyresized($mobileni, $im, 0, 0, 0, 0, $fmobiletow, $fmobiletoh, $srcw, $srch);
            }
        } else {
            return '';
        }
        if (function_exists('imagejpeg')) {
            imagejpeg($ni, $dstthumbfile);
            //´óͼƬ
            if ($make_mobile) {
                imagejpeg($mobileni, $srcfile);
            }
        } elseif (function_exists('imagepng')) {
            imagepng($ni, $dstthumbfile);
            //´óͼƬ
            if ($make_mobile) {
                imagepng($mobileni, $srcfile);
            }
        }
        imagedestroy($ni);
        if ($make_mobile) {
            imagedestroy($mobileni);
        }
    }
    imagedestroy($im);
    if (!file_exists($dstthumbfile)) {
        return '';
    } else {
        return $dstthumbfile;
    }
}
예제 #3
0
<?php

include 'Valite.php';
$name = time() . ".jpg";
$img = GrabImage("http://rkk.cdpf.org.cn/rand.jsp?tSessionId=1426303878194", $name);
if ($img) {
    echo '<img src="' . $name . '">';
} else {
    echo "false";
}
$valite = new Valite();
$valite->setImage($name);
$valite->getHec();
$ert = $valite->run();
//$ert = "1234";
// print_r($ert);
echo '</br>';
print_r($ert);
echo '</br>';
// echo '<br><img src="$name"><br>';
// echo '</br> count';
// var_dump($valite->getResult());
// echo $valite->getResult();
// count($valite->getResult());
// echo count($valite->getResult());
foreach ($valite->getResult() as $key => $value) {
    $line = '';
    foreach ($value as $key2 => $value2) {
        $line .= $value2;
    }
    echo $line . '</br>';
예제 #4
0
//单位M,后缀不要加M
//全局定义文件
//require 'define.inc.php';
//临时目录
$tempDir = "./data/thumb_temp/";
checkDir($tempDir);
//分析URL
$url = urldecode($_GET['url']);
//XSS脚本攻击探测
//include THINK_PATH.'/Vendor/xss.php';
//DetectXSS($url);
//2009-10-7 修改 将本地图片修改成相对地址,避免file_get_contents不能读取远程文件时出错(可修改php.ini  设置 allow_fopen_url 为 true)
//$url =  str_ireplace(SITE_URL,'.',$url);
if (file_exists($url)) {
    $url = $url;
} elseif ($result = GrabImage($url, $tempDir)) {
    $url = $result;
    $grab_temp_file = $result;
} else {
    $url = "./public/images/nopic.jpg";
}
//解析参数
$w = $_GET['w'] ? $_GET['w'] : '100';
//宽度
$h = $_GET['h'] ? $_GET['h'] : '100';
//高度
$t = $_GET['t'] ? $_GET['t'] : 'c';
//是否切割
$r = $_GET['r'] ? '1' : '0';
//是否覆盖
//目录名hash
예제 #5
0
                $data['code'] = '1';
            } else {
                move_uploaded_file($_FILES['img']["tmp_name"], "../../img/book/" . $picname);
                if ($q = $link->query("INSERT INTO b_product VALUES('','{$name}','{$publisher}','{$editor}','{$isbn}','{$newPrice}','{$oldPrice}','{$newDiscount}','{$oldDiscount}','{$newStock}','{$oldStock}','否','{$picname}')")) {
                    $data['msg'] = "上传成功";
                } else {
                    $data['code'] = '3';
                }
            }
        } else {
            $data['code'] = "4";
        }
    } else {
        $img = $_POST['img'];
        $picName = $isbn . '.jpg';
        GrabImage("{$img}", "../../img/book/", $picName);
        if ($q = $link->query("INSERT INTO b_product VALUES('','{$name}','{$publisher}','{$editor}','{$isbn}','{$newPrice}','{$oldPrice}','{$newDiscount}','{$oldDiscount}','{$newStock}','{$oldStock}','否','{$picName}')")) {
            $data['msg'] = "上传成功";
        } else {
            $data['code'] = '3';
        }
    }
} else {
    $data['code'] = '1';
}
$link->close();
echo json_encode($data);
//0成功
//1帐号密码不对
//3未保存到数据库成功
//4图片格式不对或者太大;
예제 #6
0
파일: post.php 프로젝트: soross/myteashop
     echo "<script>alert('新闻类型删除成功,将新闻类型列表!');location.href='../newsclass.php'</script>";
 } else {
     if (isset($_POST[task]) && "createNews" == $_POST[task]) {
         require_once "../../action/simple_html_dom.php";
         $queryRss = $db->query("select title,content,src from rss where state='0'");
         $i = 0;
         $sql = array();
         while ($rowRss = $db->fetch_array($queryRss)) {
             $html = str_get_html($rowRss[content]);
             $index = 0;
             foreach ($html->find('img') as $element) {
                 $filename = "";
                 if (strpos($element->src, "?") === false) {
                     if ($element->src != "") {
                         //echo $element->src;
                         $filename = GrabImage($element->src);
                     }
                     //../news/images/../../../news/images/18Jul2011130629.jpg
                     if ($filename != "" && $filename != false) {
                         $html->find('img', $index)->src = "../news/images/" . $filename;
                     }
                 } else {
                     $html->find('img', $index)->src = '';
                 }
                 $index++;
             }
             $sql[$i] = "insert into news(title,news_class,src,content,create_date,author) values('" . $rowRss[title] . "','-123','" . $rowRss[src] . "','" . $html . "',now(),'果果网络')";
             $i++;
             $html = '';
             $element = '';
         }
예제 #7
0
파일: getpic.php 프로젝트: vaseidong/test
 */
function GrabImage($url, $filename = "")
{
    if ($url == "") {
        return false;
    }
    if ($filename == "") {
        $ext = strrchr($url, ".");
        if ($ext != ".jpg" && $ext != ".gif" && $ext != ".png" && $ext != ".bmp" && $ext != ".swf") {
            return false;
        }
        date_default_timezone_set('UTC');
        $filename = date("dMYHis") . $ext;
    }
    ob_start();
    readfile($url);
    $img = ob_get_contents();
    ob_end_clean();
    $fp = @fopen($filename, "a");
    fwrite($fp, $img);
    fclose($fp);
    return $filename;
}
if (isset($_POST['download']) && $_POST['download'] != NULL) {
    $img = GrabImage($_POST["url"]);
    if ($img) {
        echo '<pre><img src="' . $img . '"/></pre>';
    } else {
        echo "download fail!";
    }
}