Exemple #1
0
 /**
  * 存储图片的信息的接口方法
  * @param string filename
  * @param string image_id唯一标识
  * @param string size规格类型
  * @param string 图片的名称
  * @param boolean 是否要大水印
  * @return stirng image_id唯一标识
  */
 function store($file, $image_id, $size = null, $name = null, $watermark = false)
 {
     if (!defined(FILE_STORAGER)) {
         define('FILE_STORAGER', 'filesystem');
     }
     list($w, $h, $t) = getimagesize($file);
     $extname = array(1 => '.gif', 2 => '.jpg', 3 => '.png', 6 => '.bmp');
     if (!isset($extname[$t])) {
         return false;
     }
     if ($image_id) {
         $params = $this->dump($image_id);
         if ($name) {
             $params['image_name'] = $name;
         }
         $params['image_id'] = $image_id;
     } else {
         $params['image_id'] = $this->gen_id();
         $params['image_name'] = $name;
         $params['storage'] = FILE_STORAGER;
     }
     if (substr($file, 0, 4) == 'http') {
         $params['storage'] = 'network';
         $params['url'] = $file;
         $params['ident'] = $file;
         $params['width'] = $w;
         $params['height'] = $h;
         $this->save($params);
         return $params['image_id'];
     }
     $params['watermark'] = $watermark;
     if (is_bool($params['watermark'])) {
         $params['watermark'] = $params['watermark'] ? 'true' : 'false';
     }
     $storager = new base_storager();
     $params['last_modified'] = time();
     list($url, $ident, $no) = explode("|", $storager->save_upload($file, 'image', '', $msg, $extname[$t]));
     if ($size) {
         $size = strtolower($size);
         $params[$size . '_url'] = $url;
         $params[$size . '_ident'] = $ident;
     } else {
         $params['url'] = $url;
         $params['ident'] = $ident;
         $params['width'] = $w;
         $params['height'] = $h;
     }
     parent::save($params);
     // Andrew 20120929
     // 图片上传的位置,在此处将图片转移到又拍云上
     $services = kernel::servicelist("custom.image.save");
     foreach ($services as $service) {
         $service->save($params);
     }
     return $params['image_id'];
 }
Exemple #2
0
 /**
  * 存储图片的信息的接口方法.
  *
  * @param string filename
  * @param string image_id唯一标识
  * @param string size规格类型
  * @param string 图片的名称
  * @param bool 是否要大水印
  *
  * @return stirng image_id唯一标识
  */
 public function store($file, $image_id, $size = null, $name = null, $watermark = false)
 {
     if (!defined('FILE_STORAGER')) {
         define('FILE_STORAGER', 'filesystem');
     }
     list($w, $h, $t) = getimagesize($file);
     $extname = array(1 => '.gif', 2 => '.jpg', 3 => '.png', 6 => '.bmp');
     if (!isset($extname[$t])) {
         return false;
     }
     if ($image_id) {
         $params = $this->dump($image_id);
         if ($name) {
             $params['image_name'] = $name;
         }
         $params['image_id'] = $image_id;
     } else {
         $params['image_id'] = $this->gen_id();
         $params['image_name'] = $name;
         $params['storage'] = constant('FILE_STORAGER');
     }
     if (substr($file, 0, 4) == 'http') {
         $params['storage'] = 'network';
         $params['url'] = $file;
         $params['ident'] = $file;
         $params['width'] = $w;
         $params['height'] = $h;
         $this->save($params);
         return $params['image_id'];
     }
     $params['watermark'] = 'false';
     // if(is_bool($params['watermark'])){
     // 	$params['watermark'] = $params['watermark'] ? 'true' : 'false';
     // }
     $storager = new base_storager();
     $params['last_modified'] = time();
     list($url, $ident, $no) = explode('|', $storager->save_upload($file, 'image', '', $msg, $extname[$t]));
     if ($size) {
         $size = strtolower($size);
         $params[$size . '_url'] = $url;
         $params[$size . '_ident'] = $ident;
     } else {
         $params['url'] = $url;
         $params['ident'] = $ident;
         $params['width'] = $w;
         $params['height'] = $h;
     }
     parent::save($params);
     return $params['image_id'];
 }
Exemple #3
0
 /**
  * 根据需要生成二维码的数据(URL),生成二维码,并保存到storager
  *
  * $params string $data  可以是URL,文字
  */
 public function store($data, $matrixPointSize = null, $errorCorrectionLevel = null)
 {
     $matrixPointSize = $matrixPointSize ? $matrixPointSize : $this->matrixPointSize;
     $errorCorrectionLevel = $errorCorrectionLevel ? $errorCorrectionLevel : $this->errorCorrectionLevel;
     $imageModel = app::get('image')->model('image');
     $image_id = $this->gen_qrcode_image_id($data, $matrixPointSize, $errorCorrectionLevel);
     if (!$imageModel->getRow('image_id', array('image_id' => $image_id))) {
         $filename = tempnam($this->tmp_dir, 'qrcode');
         weixin_qrcode_QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
         list($w, $h) = getimagesize($filename);
         $storager = new base_storager();
         list($url, $ident, $storage) = explode("|", $storager->save_upload($filename, 'image', '', $msg, $this->extname));
         $params = array('image_id' => $image_id, 'storage' => $storage, 'image_name' => '二维码图片', 'ident' => $ident, 'url' => $url, 'width' => $w, 'height' => $h, 'last_modified' => time());
         $imageModel->save($params);
         unlink($filename);
     }
     return $image_id;
 }
Exemple #4
0
 function store($file, $image_id, $size = null, $name = null)
 {
     list($w, $h, $t) = getimagesize($file);
     $extname = array(1 => '.gif', 2 => '.jpg', 3 => '.png', 6 => '.bmp');
     if (!isset($extname[$t])) {
         return false;
     }
     if ($image_id) {
         $params = $this->dump($image_id);
         if ($name) {
             $params['image_name'] = $name;
         }
         $params['image_id'] = $image_id;
     } else {
         $params['image_id'] = $this->gen_id();
         $params['image_name'] = $name;
         $params['storage'] = $this->app->getConf('system.default_storager');
     }
     if (substr($file, 0, 4) == 'http') {
         $params['storage'] = 'network';
         $params['url'] = $file;
         $params['ident'] = $file;
         $params['width'] = $w;
         $params['height'] = $h;
         $this->save($params);
         return $params['image_id'];
     }
     $storager = new base_storager();
     $params['last_modified'] = time();
     list($url, $ident, $no) = explode("|", $storager->save_upload($file, '', '', $msg, $extname[$t]));
     if ($size) {
         $size = strtolower($size);
         $params[$size . '_url'] = $url;
         $params[$size . '_ident'] = $ident;
     } else {
         $params['url'] = $url;
         $params['ident'] = $ident;
         $params['width'] = $w;
         $params['height'] = $h;
     }
     parent::save($params);
     return $params['image_id'];
 }
Exemple #5
-1
 public function create($intext, $long_touch)
 {
     $mdl_image = app::get('image')->model('image');
     if ($exits_image = $mdl_image->dump(md5($intext . $long_touch))) {
         return $exits_image;
     }
     $tmp_file = tempnam(TMP_DIR, 'qrcode');
     wechat_qrcode_QRcode::png($intext, $tmp_file, 'L', 8, 4);
     list($w, $h, $type) = getimagesize($tmp_file);
     if ($long_touch) {
         //加入额外图像
         $resize_tmp_file = tempnam(TMP_DIR, 'qrcode_resize');
         $image_tool = vmc::singleton('image_tools_gd');
         $image_tool->resize($tmp_file, $resize_tmp_file, $w, $h, $type, $w + 180, $h + 220, false, 20);
         $water_file = PUBLIC_DIR . '/misc/long_touch.gif';
         list($w_w, $w_h, $w_type) = getimagesize($water_file);
         $warermark_set = array('wm_opacity' => 100, 'watermark_width' => $w_w, 'watermark_height' => $w_h, 'type' => $w_type, 'src_width' => $w + 180, 'src_height' => $h + 180, 'dest_x' => ($w + 180 - 120) / 2, 'dest_y' => $h + 50);
         $image_tool->watermark($resize_tmp_file, $water_file, $warermark_set);
     }
     $storager = new base_storager();
     if ($long_touch) {
         list($url, $ident, $storage) = explode('|', $storager->save_upload($resize_tmp_file, 'image', '', $msg, '.png'));
     } else {
         list($url, $ident, $storage) = explode('|', $storager->save_upload($tmp_file, 'image', '', $msg, '.png'));
     }
     $tmp_qrcode_image = array('image_id' => md5($intext . $long_touch), 'storage' => $storage, 'image_name' => 'TMP_QRCODE', 'ident' => $ident, 'url' => $url, 'width' => $w, 'height' => $h, 'last_modified' => time());
     $mdl_image->save($tmp_qrcode_image);
     unlink($tmp_file);
     if ($long_touch) {
         unlink($resize_tmp_file);
     }
     return $tmp_qrcode_image;
 }