Exemplo n.º 1
0
 /**
  * 根据提交的图片全局配置大小,生成相应的缩略图
  * filesystem图片重新生成
  * @param null - 通过function_get_args方法来获取
  * @return null
  */
 public function command_filesystem()
 {
     $options = $this->get_options();
     $imageSet = app::get('image')->getConf('image.set');
     //print_r($imageSet);exit;
     if (isset($options['large'])) {
         $flag = 'l_ident';
         $setting = $imageSet['L'];
     } elseif (isset($options['middle'])) {
         $flag = 'm_ident';
         $setting = $imageSet['M'];
     } elseif (isset($options['small'])) {
         $flag = 's_ident';
         $setting = $imageSet['S'];
     } else {
         logger::info('Nothing to do for Image Resize');
         exit;
     }
     $pagesize = 100;
     $imgObj = kernel::single('image_clip');
     $imgMdl = app::get('image')->model('image');
     $count = $imgMdl->count(array('storage' => 'filesystem'));
     logger::info(sprintf('Total %d records', $count));
     for ($i = 0; $i < $count; $i += $pagesize) {
         $rows = $imgMdl->getList('*', array('storage' => 'filesystem'), $i, $pagesize);
         foreach ($rows as $row) {
             $orgfile = PUBLIC_DIR . '/images' . $row['ident'];
             if (empty($row[$flag])) {
                 continue;
             }
             $targetfile = PUBLIC_DIR . '/images' . $row[$flag];
             if (file_exists($orgfile) && file_exists($targetfile)) {
                 $imgObj->image_resize($imgMdl, $orgfile, $targetfile, $setting['width'], $setting['height']);
                 if ($setting['wm_type'] != 'none' && ($setting['wm_text'] || $setting['wm_image'])) {
                     image_clip::image_watermark($imgMdl, $targetfile, $setting);
                 }
                 logger::info(sprintf('%s resize(%d x %d) OK!', $targetfile, $setting['width'], $setting['height']));
             }
         }
         logger::info(sprintf('%d records Completed!', $i + count($rows)));
     }
 }
Exemplo n.º 2
0
 /**
  * 给图片打水印的接口
  * @param string image_id唯一标识
  * @param string size规格类型
  * @param boolean 是否打水印
  * @return null
  */
 function rebuild($image_id, $sizes, $watermark = true)
 {
     $storager = new base_storager();
     if ($sizes) {
         $cur_image_set = $this->app->getConf('image.set');
         $allsize = $this->app->getConf('image.default.set');
         $this->watermark_define = array();
         $this->watermark_default = '';
         if (constant("ECAE_MODE")) {
             $tmp_target = tempnam(sys_get_temp_dir(), 'img');
         } else {
             $tmp_target = tempnam(DATA_DIR, 'img');
         }
         $img = $this->dump($image_id);
         if (is_array($img)) {
             $org_file = $img['url'];
         }
         if (substr($org_file, 0, 4) == 'http') {
             if ($img['storage'] == 'network') {
                 $response = kernel::single('base_httpclient')->get($org_file);
                 if ($response === false) {
                     $data = array('image_id' => $image_id, 'last_modified' => time());
                     parent::save($data);
                     return true;
                 }
                 $image_content = $response;
             } else {
                 $image_file = $storager->worker->getFile($img['ident'], 'image');
                 if (!$image_file) {
                     return false;
                 }
                 $image_content = file_get_contents($image_file);
             }
             if (constant("ECAE_MODE")) {
                 $org_file = tempnam(sys_get_temp_dir(), 'imgorg');
             } else {
                 $org_file = tempnam(DATA_DIR, 'imgorg');
             }
             file_put_contents($org_file, $image_content);
         }
         if (!file_exists($org_file)) {
             $data = array('image_id' => $image_id, 'last_modified' => time());
             // parent::save($data);
             return true;
         }
         foreach ($sizes as $s) {
             if (isset($allsize[$s])) {
                 $w = $cur_image_set[$s]['width'];
                 $h = $cur_image_set[$s]['height'];
                 $wh = $allsize[$s]['height'];
                 $wd = $allsize[$s]['width'];
                 $w = $w ? $w : $wd;
                 $h = $h ? $h : $wh;
                 image_clip::image_resize($this, $org_file, $tmp_target, $w, $h);
                 if ($watermark && $cur_image_set[$s]['wm_type'] != 'none' && ($cur_image_set[$s]['wm_text'] || $cur_image_set[$s]['wm_image'])) {
                     $watermark = true;
                     image_clip::image_watermark($this, $tmp_target, $cur_image_set[$s]);
                 }
                 $this->store($tmp_target, $image_id, $s, null, $watermark);
                 /** 删除指定规格图片 **/
                 @unlink(ROOT_DIR . '/' . $img[strtolower($s) . '_url']);
             }
         }
         @unlink($tmp_target);
         if (strpos('imgorg', $org_file) !== false) {
             @unlink($org_file);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * 配置好图片的预览
  * @param nulll
  * @return string html预览页面
  */
 function img_preview()
 {
     $size = $_GET['size'] ? $_GET['size'] : 'L';
     $setting = $_POST['pic'][$size];
     $w = $setting['width'];
     $h = $setting['height'];
     $storager = new base_storager();
     $mdl_img = $this->app->model('image');
     $img_row = $mdl_img->dump($setting['default_image']);
     $tmp_image_id = $mdl_img->gen_id();
     if ($setting['wm_type'] == 'text' && $setting['wm_text']) {
         $url = 'http://chart.apis.google.com/chart?chst=d_text_outline&chld=000000|20|h|ffffff|_|' . urlencode($setting['wm_text']);
         if (constant("ECAE_MODE")) {
             $tmp_water_file = tempnam(sys_get_temp_dir(), 'img');
         } else {
             $tmp_water_file = tempnam(DATA_DIR, 'img');
         }
         file_put_contents($tmp_water_file, file_get_contents($url));
         $setting['wm_text_preview'] = true;
         $setting['wm_text_image'] = $tmp_water_file;
     }
     if ($img_row['storage'] == 'network') {
         if (constant("ECAE_MODE")) {
             $tmp_file = tempnam(sys_get_temp_dir(), 'img');
         } else {
             $tmp_file = tempnam(DATA_DIR, 'img');
         }
         file_put_contents($tmp_file, file_get_contents($img_row['url']));
         @unlink($tmpfile);
     } else {
         $tmp_file = $storager->worker->getFile($img_row['ident'], 'image');
     }
     if (constant("ECAE_MODE")) {
         $tmp_target = tempnam(sys_get_temp_dir(), 'img');
     } else {
         $tmp_target = tempnam(DATA_DIR, 'img');
     }
     image_clip::image_resize($mdl_img, $tmp_file, $tmp_target, $w, $h);
     if ($setting['wm_type'] != 'none' && ($setting['wm_text'] || $setting['wm_image'])) {
         image_clip::image_watermark($mdl_img, $tmp_target, $setting);
     }
     $type = getimagesize($tmp_target);
     if (file_exists($tmp_water_file)) {
         unlink($tmp_water_file);
     }
     header("Content-Type: {$type[mime]}");
     readfile($tmp_target);
     @unlink($tmp_target);
 }
Exemplo n.º 4
0
 function rebuild($image_id, $sizes, $watermark = true)
 {
     if ($sizes) {
         $cur_image_set = $this->app->getConf('image.set');
         $allsize = $this->app->getConf('image.default.set');
         $this->watermark_define = array();
         $this->watermark_default = '';
         $tmp_target = tempnam('/tmp', 'img');
         $img = $this->dump($image_id);
         if (is_array($img)) {
             $org_file = $img['url'];
         }
         if (substr($org_file, 0, 4) == 'http') {
             $response = kernel::single('base_http')->action('get', $org_file);
             if ($response === false) {
                 $data = array('image_id' => $image_id, 'last_modified' => time());
                 parent::save($data);
                 return true;
             }
             $org_file = tempnam('/tmp', 'imgorg');
             file_put_contents($org_file, file_get_contents($img['url']));
         }
         if (!file_exists($org_file)) {
             $data = array('image_id' => $image_id, 'last_modified' => time());
             parent::save($data);
             return true;
         }
         foreach ($sizes as $s) {
             if (isset($allsize[$s])) {
                 $w = $cur_image_set[$s]['width'];
                 $h = $cur_image_set[$s]['height'];
                 $wh = $allsize[$s]['height'];
                 $wd = $allsize[$s]['width'];
                 $w = $w ? $w : $wd;
                 $h = $h ? $h : $wh;
                 image_clip::image_resize($this, $org_file, $tmp_target, $w, $h);
                 if ($watermark && $cur_image_set[$s]['wm_type'] != 'none' && ($cur_image_set[$s]['wm_text'] || $cur_image_set[$s]['wm_image'])) {
                     image_clip::image_watermark($this, $tmp_target, $cur_image_set[$s]);
                 }
                 $this->store($tmp_target, $image_id, $s);
                 // error_log($tmp_target,3,'d:\text.txt');
             }
         }
         unlink($tmp_target);
     }
 }
Exemplo n.º 5
0
 /**
  * 配置好图片的预览
  * @param nulll
  * @return string html预览页面
  */
 function img_preview()
 {
     $size = $_GET['size'] ? $_GET['size'] : 'L';
     $setting = $_POST['pic'][$size];
     $w = $setting['width'];
     $h = $setting['height'];
     $storager = new base_storager();
     $mdl_img = $this->app->model('image');
     $img_row = $mdl_img->dump($setting['default_image']);
     $tmp_image_id = $mdl_img->gen_id();
     if ($setting['wm_type'] == 'text' && $setting['wm_text']) {
         //$url = 'http://chart.apis.google.com/chart?chst=d_text_outline&chld=000000|20|h|ffffff|_|'.urlencode($setting['wm_text']);
         //file_put_contents($tmp_water_file,file_get_contents($url));
         if (!function_exists('imagettftext')) {
             trigger_error('gd函数库的版本过低,请配置高于2.0.28的版本', E_USER_NOTICE);
             echo "Notice:gd函数库的版本过低,请配置高于2.0.28的版本";
             exit;
         }
         #生成文字图片
         $tmp_water_file = TMP_DIR . "/img" . time() . ".png";
         $fontfile = PUBLIC_DIR . "/app/" . $this->app->app_id . "/statics/msyh.ttf";
         $img = imagecreatetruecolor(120, 100);
         $color = imagecolorallocate($img, 255, 255, 255);
         imagecolortransparent($img, $color);
         imagefill($img, 0, 0, $color);
         $textcolor = imagecolorallocate($img, 0, 0, 0);
         imagettftext($img, 16, 0, 0, 50, $textcolor, $fontfile, $setting['wm_text']);
         imagesavealpha($img, true);
         imagepng($img, $tmp_water_file);
         imagedestroy($img);
         $setting['wm_text_preview'] = true;
         $setting['wm_text_image'] = $tmp_water_file;
     }
     if ($img_row['storage'] == 'network') {
         $tmp_file = tempnam(TMP_DIR, 'img');
         file_put_contents($tmp_file, file_get_contents($img_row['url']));
     } else {
         $tmp_file = $storager->worker->getFile($img_row['ident'], 'image');
     }
     $tmp_target = tempnam(TMP_DIR, 'img');
     image_clip::image_resize($mdl_img, $tmp_file, $tmp_target, $w, $h);
     if ($setting['wm_type'] != 'none' && ($setting['wm_text'] || $setting['wm_image'])) {
         image_clip::image_watermark($mdl_img, $tmp_target, $setting);
     }
     $type = getimagesize($tmp_target);
     header("Content-Type: {$type[mime]}");
     readfile($tmp_target);
 }
Exemplo n.º 6
0
 /**
  * 配置好图片的预览
  * @param nulll
  * @return string html预览页面
  */
 function img_preview()
 {
     $size = $_GET['size'] ? $_GET['size'] : 'L';
     $setting = $_POST['pic'][$size];
     $w = $setting['width'];
     $h = $setting['height'];
     $storager = new base_storager();
     $mdl_img = $this->app->model('image');
     $img_row = $mdl_img->dump($setting['default_image']);
     $tmp_image_id = $mdl_img->gen_id();
     if ($setting['wm_type'] == 'text' && $setting['wm_text']) {
         if (!function_exists('imagettftext')) {
             trigger_error('gd函数库的版本过低,请配置高于2.0.28的版本', E_USER_NOTICE);
             echo "Notice:gd函数库的版本过低,请配置高于2.0.28的版本";
             exit;
         }
         #生成文字图片
         //$tmp_water_file = TMP_DIR."/img".time().".png";
         $tmp_water_file = tempnam(TMP_DIR, 'img') . time() . ".png";
         $fontfile = PUBLIC_DIR . "/app/" . app::get('image')->app_id . "/statics/msyh.ttf";
         $img = imagecreatetruecolor(120, 100);
         $color = imagecolorallocate($img, 255, 255, 255);
         imagecolortransparent($img, $color);
         imagefill($img, 0, 0, $color);
         $textcolor = imagecolorallocate($img, 0, 0, 0);
         imagettftext($img, 16, 0, 0, 50, $textcolor, $fontfile, $setting['wm_text']);
         imagesavealpha($img, true);
         imagepng($img, $tmp_water_file);
         imagedestroy($img);
         $setting['wm_text_preview'] = true;
         $setting['wm_text_image'] = $tmp_water_file;
     }
     $objLibImage = kernel::single('image_data_image');
     $tmp_file = $objLibImage->fetch($img_row['image_id']);
     $tmp_target = tempnam(TMP_DIR, 'img');
     image_clip::image_resize($tmp_file, $tmp_target, $w, $h);
     if ($setting['wm_type'] != 'none' && ($setting['wm_text'] || $setting['wm_image'])) {
         image_clip::image_watermark($objLibImage, $tmp_target, $setting);
     }
     unlink($tmp_water_file);
     $type = getimagesize($tmp_target);
     header("Content-Type: {$type[mime]}");
     readfile($tmp_target);
 }