示例#1
0
文件: Imager.php 项目: infrajs/imager
 public static function prepareSrc($src, $num = 0)
 {
     $conf = static::$conf;
     $ext = Path::getExt($src);
     if (preg_match("/^https{0,1}:\\/\\//", $src)) {
         //$src=Path::theme('-imager/noimage.png');
         $src = Imager::remote($src);
     } else {
         if ($ext == 'php') {
             //Такое может быть если путь до картинки передан тоже с imager то есть двойной вызов
             $src = Imager::getReal($src);
         } else {
             $src = Path::theme($src);
         }
     }
     if ($src && is_dir($src)) {
         //папка смотрим в ней для src
         $list = array();
         array_map(function ($file) use(&$list, $src) {
             if ($file[0] == '.') {
                 return;
             }
             if (!is_file($src . $file)) {
                 return;
             }
             $ext = Path::getExt($file);
             if (in_array($ext, Imager::$exts)) {
                 $list[] = $file;
             }
         }, scandir($src));
         if (empty($list[$num])) {
             $src = false;
         } else {
             $src = $src . $list[$num];
         }
     }
     return $src;
 }
示例#2
0
文件: index.php 项目: infrajs/imager
 $data = Imager::scale($src, $w, $h, $crop, $top);
 if (!$data) {
     die('Resize Error');
 }
 if ($type == 'png') {
     $data = Imager::optipng($data, md5($src . $w . $h . $crop . $top));
     if (!$data) {
         die('Optipng Error');
     }
 }
 $br = infra_imager_browser();
 $name = preg_replace("/(.*\\/)*/", '', $isrc);
 if (!$name) {
     $name = Path::encode($isrc);
 }
 $name = Imager::toutf($name);
 if (!preg_match('/ff/', $br)) {
     $name = rawurlencode($name);
 }
 if (preg_match('/ie6/', $br)) {
     $name = preg_replace("/\\s/", '%20', $name);
 }
 if (!$type) {
     $type = 'image/jpeg';
 }
 $ans = array('name' => $name, 'type' => $type);
 //return $data;
 //}, $args, isset($_GET['re']));
 //)
 file_put_contents($cachesrc . '.data', $data);
 file_put_contents($cachesrc, Load::json_encode($ans));