상속: extends Controller
예제 #1
0
 /**
  * 
  * @param string $filename
  * @param image $sourceImage
  * @param rectangle $rectangle
  */
 public function __construct($filename, $sourceImage, $rectangle)
 {
     parent::__construct($filename);
     $this->setType($sourceImage->getType());
     $this->fromArea($sourceImage, $rectangle);
     $this->save();
 }
예제 #2
0
function nv_resize_crop_image($img_path, $width, $height, $module_name = '', $id = 0)
{
    $new_img_path = '';
    if (file_exists($img_path)) {
        $imginfo = nv_is_image($img_path);
        $basename = basename($img_path);
        if ($imginfo['width'] > $width or $imginfo['height'] > $height) {
            $basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', $module_name . '_' . $id . '_\\1_' . $width . '-' . $height . '\\2', $basename);
            if (file_exists(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . $basename)) {
                $new_img_path = NV_BASE_SITEURL . NV_TEMP_DIR . '/' . $basename;
            } else {
                $img_path = new image($img_path, NV_MAX_WIDTH, NV_MAX_HEIGHT);
                $thumb_width = $width;
                $thumb_height = $height;
                $maxwh = max($thumb_width, $thumb_height);
                if ($img_path->fileinfo['width'] > $img_path->fileinfo['height']) {
                    $width = 0;
                    $height = $maxwh;
                } else {
                    $width = $maxwh;
                    $height = 0;
                }
                $img_path->resizeXY($width, $height);
                $img_path->cropFromCenter($thumb_width, $thumb_height);
                $img_path->save(NV_ROOTDIR . '/' . NV_TEMP_DIR, $basename);
                if (file_exists(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . $basename)) {
                    $new_img_path = NV_BASE_SITEURL . NV_TEMP_DIR . '/' . $basename;
                }
            }
        }
    }
    return $new_img_path;
}
예제 #3
0
 public function index()
 {
     $database = new database();
     $query = $database->query();
     $images = new image($query);
     $currentActive = $images->fetchCurrentActive();
     $this->setVar('currentActive', $currentActive);
 }
예제 #4
0
 function common()
 {
     global $_G;
     if (!defined('IN_DISCUZ') || empty($_GET['aid']) || empty($_GET['size']) || empty($_GET['key'])) {
         header('location: ' . $_G['siteurl'] . 'static/image/common/none.gif');
         exit;
     }
     $allowsize = array('960x960', '268x380', '266x698', '2000x2000');
     if (!in_array($_GET['size'], $allowsize)) {
         header('location: ' . $_G['siteurl'] . 'static/image/common/none.gif');
         exit;
     }
     $nocache = !empty($_GET['nocache']) ? 1 : 0;
     $daid = intval($_GET['aid']);
     $type = !empty($_GET['type']) ? $_GET['type'] : 'fixwr';
     list($w, $h) = explode('x', $_GET['size']);
     $dw = intval($w);
     $dh = intval($h);
     $thumbfile = 'image/' . $daid . '_' . $dw . '_' . $dh . '.jpg';
     $parse = parse_url($_G['setting']['attachurl']);
     $attachurl = !isset($parse['host']) ? $_G['siteurl'] . $_G['setting']['attachurl'] : $_G['setting']['attachurl'];
     if (!$nocache) {
         if (file_exists($_G['setting']['attachdir'] . $thumbfile)) {
             dheader('location: ' . $attachurl . $thumbfile);
         }
     }
     define('NOROBOT', TRUE);
     $id = !empty($_GET['atid']) ? $_GET['atid'] : $daid;
     if (md5($id . '|' . $dw . '|' . $dh) != $_GET['key']) {
         dheader('location: ' . $_G['siteurl'] . 'static/image/common/none.gif');
     }
     if ($attach = C::t('forum_attachment_n')->fetch('aid:' . $daid, $daid, array(1, -1))) {
         if (!$dw && !$dh && $attach['tid'] != $id) {
             dheader('location: ' . $_G['siteurl'] . 'static/image/common/none.gif');
         }
         dheader('Expires: ' . gmdate('D, d M Y H:i:s', TIMESTAMP + 3600) . ' GMT');
         if ($attach['remote']) {
             $filename = $_G['setting']['ftp']['attachurl'] . 'forum/' . $attach['attachment'];
         } else {
             $filename = $_G['setting']['attachdir'] . 'forum/' . $attach['attachment'];
         }
         require_once libfile('class/image');
         $img = new image();
         if ($img->Thumb($filename, $thumbfile, $w, $h, $type)) {
             if ($nocache) {
                 dheader('Content-Type: image');
                 @readfile($_G['setting']['attachdir'] . $thumbfile);
                 @unlink($_G['setting']['attachdir'] . $thumbfile);
             } else {
                 dheader('location: ' . $attachurl . $thumbfile);
             }
         } else {
             dheader('Content-Type: image');
             @readfile($filename);
         }
     }
     exit;
 }
예제 #5
0
 /**
  *
  * @param image $image
  * @param rectangle $rectangle
  */
 public function fromArea($image, $sourceImage, $rectangle)
 {
     $image->init();
     $sourceImage->init();
     if (is_resource($sourceImage->meta)) {
         $image->meta = imagecreatetruecolor($rectangle->getWidth(), $rectangle->getHeight());
         $this->_thumbnail($sourceImage->meta, $image->meta, $rectangle);
     }
 }
 function nv_news_block_newscenter($block_config)
 {
     global $module_data, $module_name, $module_file, $global_array_cat, $global_config, $lang_module, $db, $module_config, $module_info;
     $module_name = 'news';
     $module_data = 'news';
     $xtpl = new XTemplate('block_newscenter.tpl', NV_ROOTDIR . '/themes/' . $module_info['template'] . '/blocks');
     $xtpl->assign('lang', $lang_module);
     $xtpl->assign('NV_BASE_SITEURL', NV_BASE_SITEURL);
     $db->sqlreset()->select('id, catid, publtime, title, alias, hometext, homeimgthumb, homeimgfile')->from(NV_PREFIXLANG . '_' . $module_data . '_rows')->where('status= 1')->order('publtime DESC')->limit(5);
     $list = nv_db_cache($db->sql(), 'id', $module_name);
     $i = 1;
     foreach ($list as $row) {
         $row['publtime'] = nv_date('m/d/Y', $row['publtime']);
         $row['link'] = NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=' . $global_array_cat[$row['catid']]['alias'] . '/' . $row['alias'] . '-' . $row['id'] . $global_config['rewrite_exturl'];
         $row['title0'] = nv_clean60(strip_tags($row['title']), $i == 1 ? 50 : 30);
         $row['hometext'] = nv_clean60(strip_tags($row['hometext']), 260);
         $image = NV_UPLOADS_REAL_DIR . '/' . $module_name . '/' . $row['homeimgfile'];
         if ($row['homeimgfile'] != '' and file_exists($image)) {
             if ($i == 1) {
                 $width = 570;
                 $height = 490;
             } else {
                 $width = 270;
                 $height = 230;
             }
             $row['imgsource'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module_name . '/' . $row['homeimgfile'];
             $imginfo = nv_is_image($image);
             $basename = basename($image);
             if ($imginfo['width'] > $width or $imginfo['height'] > $height) {
                 $basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', $module_name . '_' . $row['id'] . '_\\1_' . $width . '-' . $height . '\\2', $basename);
                 if (file_exists(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . $basename)) {
                     $row['imgsource'] = NV_BASE_SITEURL . NV_TEMP_DIR . '/' . $basename;
                 } else {
                     require_once NV_ROOTDIR . '/includes/class/image.class.php';
                     $_image = new image($image, NV_MAX_WIDTH, NV_MAX_HEIGHT);
                     $_image->cropFromCenter($width, $height);
                     $_image->save(NV_ROOTDIR . '/' . NV_TEMP_DIR, $basename);
                     if (file_exists(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . $basename)) {
                         $row['imgsource'] = NV_BASE_SITEURL . NV_TEMP_DIR . '/' . $basename;
                     }
                 }
             }
         } elseif (nv_is_url($row['homeimgfile'])) {
             $row['imgsource'] = $row['homeimgfile'];
         } elseif (!empty($module_config[$module_name]['show_no_image'])) {
             $row['imgsource'] = NV_BASE_SITEURL . $module_config[$module_name]['show_no_image'];
         } else {
             $row['imgsource'] = NV_BASE_SITEURL . 'themes/' . $global_config['site_theme'] . '/images/no-image.png';
         }
         $xtpl->assign('main' . $i, $row);
         ++$i;
     }
     $xtpl->parse('main');
     return $xtpl->text('main');
 }
예제 #7
0
 /**
  *
  * @param image $image
  * @param rectangle $rectangle
  */
 public function fromArea($image, $sourceImage, $rectangle)
 {
     $image->init();
     $sourceImage->init();
     if ($image->meta instanceof Imagick) {
         if ($sourceImage->meta instanceof Imagick) {
             $source = $sourceImage->meta->coalesceImages();
             $this->_thumbnail($sourceImage->meta, $image->meta, $rectangle);
         }
     }
 }
예제 #8
0
 public function _unlikeImg($id)
 {
     $mem = new Memcache();
     $mem->connect("127.0.0.1", 11211);
     $like = $mem->get("f_" . $_SESSION['USERID']);
     $like[$id] = NULL;
     $mem->set("f_" . $_SESSION['USERID'], $like, 0, 0);
     $recommender = recommender::getInstance();
     $recommender->set_rating($_SESSION['USERID'], $id, 0);
     echo json_encode("true");
     $this->model->Del_By_ImageId($id);
     $img = new image();
     $img->removefromfavor($id);
 }
예제 #9
0
 function common()
 {
     global $_G;
     if (empty($_G['uid'])) {
         self::error('api_uploadavatar_unavailable_user');
     }
     if (empty($_FILES['Filedata'])) {
         self::error('api_uploadavatar_unavailable_pic');
     }
     list($width, $height, $type, $attr) = getimagesize($_FILES['Filedata']['tmp_name']);
     $imgtype = array(1 => '.gif', 2 => '.jpg', 3 => '.png');
     $filetype = $imgtype[$type];
     if (!$filetype) {
         $filetype = '.jpg';
     }
     $avatarpath = $_G['setting']['attachdir'];
     $tmpavatar = $avatarpath . './temp/upload' . $_G['uid'] . $filetype;
     file_exists($tmpavatar) && @unlink($tmpavatar);
     if (@copy($_FILES['Filedata']['tmp_name'], $tmpavatar) || @move_uploaded_file($_FILES['Filedata']['tmp_name'], $tmpavatar)) {
         @unlink($_FILES['Filedata']['tmp_name']);
         list($width, $height, $type, $attr) = getimagesize($tmpavatar);
         if ($width < 10 || $height < 10 || $type == 4) {
             @unlink($tmpavatar);
             self::error('api_uploadavatar_unusable_image');
         }
     } else {
         @unlink($_FILES['Filedata']['tmp_name']);
         self::error('api_uploadavatar_service_unwritable');
     }
     $tmpavatarbig = './temp/upload' . $_G['uid'] . 'big' . $filetype;
     $tmpavatarmiddle = './temp/upload' . $_G['uid'] . 'middle' . $filetype;
     $tmpavatarsmall = './temp/upload' . $_G['uid'] . 'small' . $filetype;
     $image = new image();
     if ($image->Thumb($tmpavatar, $tmpavatarbig, 200, 250, 1) <= 0) {
         //$image->error();
         self::error('api_uploadavatar_unusable_image');
     }
     if ($image->Thumb($tmpavatar, $tmpavatarmiddle, 120, 120, 1) <= 0) {
         //$image->error();
         self::error('api_uploadavatar_unusable_image');
     }
     if ($image->Thumb($tmpavatar, $tmpavatarsmall, 48, 48, 2) <= 0) {
         //$image->error();
         self::error('api_uploadavatar_unusable_image');
     }
     $this->tmpavatar = $tmpavatar;
     $this->tmpavatarbig = $avatarpath . $tmpavatarbig;
     $this->tmpavatarmiddle = $avatarpath . $tmpavatarmiddle;
     $this->tmpavatarsmall = $avatarpath . $tmpavatarsmall;
 }
예제 #10
0
 /**
  * Gibt Dateiindex in Datenbank zurück
  * @param int $limit
  * @param int $offset
  * @return array:\fpcm\model\files\image
  */
 public function getDatabaseList($limit = false, $offset = false)
 {
     $where = '1=1' . $this->dbcon->orderBy(array('filetime DESC'));
     if ($limit !== false && $offset !== false) {
         $where .= ' ' . $this->dbcon->limitQuery($limit, $offset);
     }
     $images = $this->dbcon->fetch($this->dbcon->select($this->table, '*', $where), true);
     $res = array();
     foreach ($images as $image) {
         $imageObj = new image('', '', '', false);
         $imageObj->createFromDbObject($image);
         $res[$image->filename] = $imageObj;
     }
     return $res;
 }
예제 #11
0
 public function doPOST()
 {
     require DB_PATH . '/core/lib/image.php';
     $img = new image($this->db);
     try {
         $img->upload($this->auth->authenticated());
         redirect('view', $img->getentryid());
     } catch (ImageException $e) {
         if ($e->rollback) {
             $img->rollback();
         }
         $_SESSION['upload_errors'][] = $e->getMessage();
         redirect('upload');
     }
 }
예제 #12
0
파일: album.php 프로젝트: plusjade/plusjade
 public function _index($album, $sub_tool = FALSE)
 {
     # this is a hack for allowed sub_tools only.
     if (!is_object($album)) {
         $album = ORM::factory('album')->where('fk_site', $this->site_id)->find($album);
         if (!$album->loaded) {
             return $this->wrap_tool('album error, please contact support', 'album', $album);
         }
     }
     # set the thumbnail size USES TOGGLE:
     $thumb_size = (isset($album->toggle) and is_numeric($album->toggle)) ? $album->toggle : 75;
     # images
     $images = json_decode($album->images);
     if (NULL === $images or !is_array($images)) {
         return $this->wrap_tool('no images.', 'album', $album);
     }
     foreach ($images as $image) {
         $image->thumb = image::thumb($image->path, $thumb_size);
     }
     $display_view = empty($album->view) ? 'lightbox' : $album->view;
     $primary = $this->{$display_view}($album, $images);
     # add custom javascript;
     $primary->global_readyJS(self::javascripts($album));
     return $this->wrap_tool($primary, 'album', $album, $sub_tool);
 }
예제 #13
0
 function getHtml($Recipient = null, $ZendMail = null)
 {
     $html = $this->html;
     $data = $Recipient ? unserialize($Recipient->data) : array();
     qg::fire('mail::gethtml', array('Mail' => $this, 'Recipient' => $Recipient, 'html' => &$html, 'data' => &$data, 'ZendMail' => $ZendMail));
     if ($data) {
         $T = new template($data);
         $html = $T->renderMarker($html);
     }
     if ($ZendMail) {
         // deprecated
         preg_match_all("#<img.*?src=['\"]file://([^'\"]+)#i", $html, $matches);
         $matches = array_unique($matches[1]);
         if ($matches) {
             $ZendMail->setType(Zend_Mime::MULTIPART_RELATED);
             foreach ($matches as $key => $filename) {
                 if (!is_readable($filename) || !image::able($filename)) {
                     continue;
                 }
                 $at = $ZendMail->createAttachment(file_get_contents($filename));
                 $at->type = extensionToMime(preg_replace('/.*\\.([^.]+$)/', '$1', $filename));
                 $at->disposition = Zend_Mime::DISPOSITION_INLINE;
                 $at->id = 'i' . md5_file($filename);
                 $html = str_replace('file://' . $filename, 'cid:' . $at->id, $html);
                 trigger_error('error: auto inline images are deprecated!');
             }
         }
     }
     return $html;
 }
예제 #14
0
 public function manage()
 {
     $album = $this->get_parent('album');
     if ($_POST) {
         if (NULL === json_decode($_POST['images'])) {
             die('data is not properly formed JSON');
         }
         $album->images = $_POST['images'];
         $album->save();
         die('Album saved');
     }
     # images
     $images = json_decode($album->images);
     if (NULL === $images) {
         $images = array();
     }
     foreach ($images as $image) {
         $image->thumb = image::thumb($image->path);
     }
     $primary = new View('edit_album/manage');
     $primary->album = $album;
     $primary->images = $images;
     $primary->img_path = $this->assets->assets_url();
     die($primary);
 }
예제 #15
0
 public function resize($width, $height = NULL)
 {
     if ($height === NULL) {
         $height = $width;
     }
     return image::resize($this->file->getPath(), $this->file->getPath(), $width, $height);
 }
예제 #16
0
function get_ami_deployment_image_rootdevice_identifier($id)
{
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_ADMIN;
    global $event;
    $rootdevice_identifier_array = array();
    $image = new image();
    $image_id_list = $image->get_ids();
    foreach ($image_id_list as $id => $ikey) {
        $image_tmp = new image();
        $image_tmp->get_instance_by_id($id);
        if ($image_tmp->type === "ami-deployment") {
            $rootdevice_identifier_array[] = array("value" => $image_tmp->rootdevice, "label" => $image_tmp->name);
        }
    }
    return $rootdevice_identifier_array;
}
예제 #17
0
 function uploadFile($filepath)
 {
     // getting paths
     $uploadedfile = $filepath;
     $uploaddir = $this->uploadDir;
     // creating Directory of logged in  userid
     $dir = $_SESSION['foongigs_userid'];
     if ($dir) {
         if (!file_exists($uploaddir . $dir . "/")) {
             mkdir($uploaddir . $dir . "/", 0777);
         }
     }
     // creating files
     $image = new image($imagepath);
     $this->randfilename = $image->getFileName();
     $this->fileext = $image->getFileExtension();
     $this->width = $image->getImageHeight();
     $this->height = $image->getImageWidth();
     for ($i = 0; $i < count($size); $i++) {
         $dimension = explode("x", $size[$i]);
         $destination = $uploaddir . $dir . "/" . $this->randfilename . "_" . $size[$i] . "." . $this->fileext;
         $image->createAndResize($destination, $dimension[0], $dimension[1], $this->imageQuality);
     }
     // Upload Original File....
     $destination = $uploaddir . $dir . "/" . $this->randfilename . "_original" . "." . $this->fileext;
     $image->moveTo($destination);
 }
예제 #18
0
 public function checkFile($file, array $config)
 {
     $driver = isset($config['imageDriversPriority']) ? image::getDriver(explode(" ", $config['imageDriversPriority'])) : "gd";
     $img = image::factory($driver, $file);
     if ($img->initError) {
         return "Unknown image format/encoding.";
     }
     return true;
 }
 public function uploadAction($obj)
 {
     $image = new image();
     $image->setObj($obj);
     $form = $this->createFormBuilder($image)->add('name')->add('description')->add('file', 'file')->add('typeAnnonceClient')->getForm();
     $test = 0;
     if ($this->getRequest()->isMethod('POST')) {
         $form->handleRequest($this->getRequest());
         if ($form->isValid()) {
             $image->obj = $obj;
             $image->upload();
             $em = $this->getDoctrine()->getManager();
             $em->persist($image);
             $em->flush();
             $test = 1;
         }
     }
     return $this->render('ApplicationHomeBundle:Image:new.html.twig', array('image' => $image, 'form' => $form->createView(), 'obj' => $obj, 'test' => $test));
 }
예제 #20
0
 static function avatar($image, $true_size, $size_data = array(100, 50, 32), $save_name, $save_dir = '')
 {
     foreach ($size_data as $target_size) {
         $target_img = image::create($target_size, $target_size, 'ffffff', true);
         $param = array(0, 0, 0, 0, $target_size, $target_size, $true_size, $true_size);
         $copy_result = image::copy($target_img, $image, $param, 5);
         if ($copy_result) {
             image::save($target_img, $save_name . '.gif', $save_dir . $target_size . '/');
         }
     }
 }
예제 #21
0
    function thumb($image, $filename = '', $maxwidth = 200, $maxheight = 200, $suffix='', $autocut = 0, $ftp = 0) {
		if(!$this->thumb_enable || !$this->check($image)) return false;
        $info  = image::info($image);
        if($info === false) return false;
		$srcwidth  = $info['width'];
		$srcheight = $info['height'];
		$pathinfo = pathinfo($image);
		$type =  $pathinfo['extension'];
		if(!$type) $type = $info['type'];
		$type = strtolower($type);
		unset($info);

		$creat_arr = $this->getpercent($srcwidth,$srcheight,$maxwidth,$maxheight);
		$createwidth = $width = $creat_arr['w'];
		$createheight = $height = $creat_arr['h'];

		$psrc_x = $psrc_y = 0;
		if($autocut && $maxwidth > 0 && $maxheight > 0) {
			if($maxwidth/$maxheight<$srcwidth/$srcheight && $maxheight>=$height) {
				$width = $maxheight/$height*$width;
				$height = $maxheight;
			}elseif($maxwidth/$maxheight>$srcwidth/$srcheight && $maxwidth>=$width) {
				$height = $maxwidth/$width*$height;
				$width = $maxwidth;
			}
			$createwidth = $maxwidth;
			$createheight = $maxheight;
		}
		$createfun = 'imagecreatefrom'.($type=='jpg' ? 'jpeg' : $type);
		$srcimg = $createfun($image);
		if($type != 'gif' && function_exists('imagecreatetruecolor'))
			$thumbimg = imagecreatetruecolor($createwidth, $createheight); 
		else
			$thumbimg = imagecreate($width, $height); 

		if(function_exists('imagecopyresampled'))
			imagecopyresampled($thumbimg, $srcimg, 0, 0, $psrc_x, $psrc_y, $width, $height, $srcwidth, $srcheight); 
		else
			imagecopyresized($thumbimg, $srcimg, 0, 0, $psrc_x, $psrc_y, $width, $height,  $srcwidth, $srcheight); 
		if($type=='gif' || $type=='png') {
			$background_color  =  imagecolorallocate($thumbimg,  0, 255, 0);  //  指派一个绿色  
			imagecolortransparent($thumbimg, $background_color);  //  设置为透明色,若注释掉该行则输出绿色的图 
		}
		if($type=='jpg' || $type=='jpeg') imageinterlace($thumbimg, $this->interlace);
		$imagefun = 'image'.($type=='jpg' ? 'jpeg' : $type);
		if(empty($filename)) $filename  = substr($image, 0, strrpos($image, '.')).$suffix.'.'.$type;
		$imagefun($thumbimg, $filename);
		imagedestroy($thumbimg);
		imagedestroy($srcimg);
		if($ftp) {
			@unlink($image);
		}
		return $filename;
    }
예제 #22
0
 public function upload()
 {
     if (null === $this->logo) {
         return;
     }
     // if there is an error when moving the logo, an exception will
     // be automatically thrown by move(). This will properly prevent
     // the entity from being persisted to the database on error
     $this->logo->move($this->getUploadRootDir(), $this->path);
     unset($this->logo);
 }
예제 #23
0
 public function submit()
 {
     $post = $_POST;
     $file = $_FILES['file_upload'];
     $request = new post($post, $file);
     $submission = $request->getPost();
     $database = new database();
     $query = $database->query();
     $image = new image($query, $submission);
     // upload image
     try {
         $upload = $image->upload();
     } catch (Exception $e) {
         echo 'Message: ' . $e->getMessage();
     }
     // insert image
     if (isset($upload) && $upload == 'success') {
         $images = new image($query, $submission);
         $image->insert();
     }
 }
예제 #24
0
파일: index.php 프로젝트: xibijj/VCR
function mkvcode2($f_name)
{
    $vcode = '';
    $tmp_vcode = 'vcode_tmp.png';
    include 'img.class.php';
    $image = new image($f_name, 2, "0,0", "80,20", $tmp_vcode);
    $image->outimage();
    usleep(50000);
    $cmd = "tesseract {$tmp_vcode} vcode";
    system($cmd);
    if (file_exists('vcode.txt')) {
        $vcode = file_get_contents('vcode.txt');
        $vcode = trim($vcode);
        $vcode = str_replace(' ', '', $vcode);
    }
    if (strlen($vcode) > 3) {
        return $vcode;
    } else {
        //return mkvcode();
    }
}
예제 #25
0
파일: image.php 프로젝트: revcozmo/dating
 public static function get()
 {
     $vars = self::get_path_variables();
     if (count($vars) == 1) {
         $image = \lib\image::get(reset($vars));
         header("Content-type: image/{$image['type']}");
         self::$return_json = false;
         return $image['image'];
     } else {
         if (count($vars) == 2 && $vars[0] == 'user') {
             $images = \lib\image::get_user_images($vars[1]);
             return $images;
         }
     }
 }
예제 #26
0
 protected static function _cachePhoto($cache_dir, $file_name, $file_type)
 {
     if (!$file_name || !$file_type) {
         return false;
     }
     //生产缓存文件(缩放后的图)
     $cache_path_name = ROOT_PATH . $cache_dir;
     $cache_file_path = $cache_path_name . md5($file_name) . '.' . $file_type;
     //目录不存在,创建目录
     if (!is_dir($cache_path_name)) {
         @mkdir($cache_path_name, 0755, true);
     }
     if (!is_file($cache_file_path)) {
         // if( strstr( $file_name, PhotoM::uploadPath ) ){//旧的存储方式
         // 	image::getobj()->imageinit( ROOT_PATH . $file_name, 1, 800, 800, 0, 0, $cache_file_path )->outimage();
         // }else{//新的存储方式
         // 	image::getobj()->imageinit( ROOT_PATH . PhotoM::uploadPath . $file_name, 1, 800, 800, 0, 0, $cache_file_path )->outimage();
         // }
         image::getobj()->imageinit(ROOT_PATH . PhotoM::uploadPath . $file_name, 1, 800, 800, 0, 0, $cache_file_path)->outimage();
     }
 }
예제 #27
0
 static function transform1($params)
 {
     $url = $params['image'];
     $data = $params['data'];
     $info = image::image_info($url);
     $path = $info['path'];
     if (!io::file_exists($path)) {
         throw new \Exception(resources::message('FILE_NOT_EXISTS', $path));
     }
     if (meta::exists($info['id'])) {
         $meta = meta::get($info['id']);
         $spath = util::apath($meta['orig']);
         $data = isset($meta['data']) ? image::combine_transform($meta['data'], $data) : $data;
     } else {
         $spath = $path;
     }
     $id = util::id();
     $name = $id . '.' . $info['ext'];
     $dpath = DRAFT_CONTENT_DIR . '/' . $name;
     image::transform_image($spath, $dpath, $data);
     meta::put($id, array('orig' => util::rpath($spath), 'oid' => $info['id'], 'path' => util::rpath($dpath), 'name' => $name, 'data' => $data, 'image' => true));
     return array('status' => 0, 'url' => DRAFT_CONTENT_URL . '/' . $name);
 }
예제 #28
0
파일: file.php 프로젝트: dalinhuang/zotop
 public function upload()
 {
     //上传文件
     $this->files = $this->upload->save();
     //设置错误
     if ($this->upload->error()) {
         $this->error($this->upload->error(), $this->upload->msg());
     }
     if (is_array($this->files)) {
         //保存文件
         $ip = ip::current();
         $userid = $this->_user['id'];
         $description = (array) $this->description;
         foreach ($this->files as $key => $file) {
             $file['id'] = $file['id'];
             $file['parentid'] = $file['id'];
             $file['globalid'] = $this->globalid;
             $file['groupid'] = $this->folderid;
             $file['field'] = $this->field;
             $file['type'] = file::type($file['path']);
             $file['description'] = empty($description[$key]) ? $file['description'] : $description[$key];
             $file['userid'] = $userid;
             $file['status'] = (int) $this->status;
             $file['createip'] = $ip;
             $file['createtime'] = TIME;
             if ($file['type'] == 'image' || preg_match('/^(jpeg|jpeg|png|gif|bmp|ico|tif|tiff|psd|xbm|xcf)$/', $file['ext'])) {
                 $info = image::info($file['path']);
                 $file['width'] = (int) $info['width'];
                 $file['height'] = (int) $info['height'];
             }
             $this->insert($file);
         }
         return $this->files;
     }
     return array();
 }
예제 #29
0
 /**
  * Führt Upload via HTML-Form + PHP in Dateimanager durch
  * @param int $userId
  * @return array
  */
 public function processUpload($userId)
 {
     $this->uploader = $this->events->runEvent('fileUploadPhpBefore', $this->uploader);
     $tempNames = $this->uploader['tmp_name'];
     $fileNames = $this->uploader['name'];
     $fileTypes = $this->uploader['type'];
     $res = array('error' => array(), 'success' => array());
     foreach ($tempNames as $key => $value) {
         if (!is_uploaded_file($value) || !isset($fileNames[$key]) || !isset($fileTypes[$key])) {
             continue;
         }
         $ext = pathinfo($fileNames[$key], PATHINFO_EXTENSION);
         $ext = $ext ? strtolower($ext) : '';
         if (isset($fileTypes[$key]) && !in_array($fileTypes[$key], image::$allowedTypes) || !in_array($ext, image::$allowedExts)) {
             trigger_error('Unsupported filetype in ' . $fileNames[$key]);
             $res['error'][$key] = $fileNames[$key];
             continue;
         }
         $fileName = \fpcm\classes\baseconfig::$uploadDir . $fileNames[$key];
         $image = new image($fileNames[$key]);
         if (!$image->moveUploadedFile($value)) {
             trigger_error('Unable to move uploaded to to uploader folder! ' . $fileNames[$key]);
             $res['error'][$key] = $fileNames[$key];
             continue;
         }
         $image->createThumbnail();
         $image->setFiletime(time());
         $image->setUserid($userId);
         if (!$image->save()) {
             trigger_error('Unable to add uploaded file to database list! ' . $fileNames[$key]);
             $res['error'][$key] = $fileNames[$key];
             continue;
         }
         $fmThumbs = new \fpcm\model\crons\fmThumbs('fmThumbs');
         $fmThumbs->run();
         $res['success'][$key] = $fileNames[$key];
     }
     $this->events->runEvent('fileUploadPhpAfter', array('uploader' => $this->uploader, 'results' => $res));
     return $res;
 }
 function creat_thumbs($id, $homeimgfile, $module_name, $width = 200, $height = 150)
 {
     if ($width >= $height) {
         $rate = $width / $height;
     } else {
         $rate = $height / $width;
     }
     $image = NV_UPLOADS_REAL_DIR . '/' . $module_name . '/' . $homeimgfile;
     if ($homeimgfile != '' and file_exists($image)) {
         $imgsource = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module_name . '/' . $homeimgfile;
         $imginfo = nv_is_image($image);
         $basename = $module_name . $width . 'x' . $height . '-' . $id . '-' . md5_file($image) . '.' . $imginfo['ext'];
         if (file_exists(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . $basename)) {
             $imgsource = NV_BASE_SITEURL . NV_TEMP_DIR . '/' . $basename;
         } else {
             require_once NV_ROOTDIR . '/includes/class/image.class.php';
             $_image = new image($image, NV_MAX_WIDTH, NV_MAX_HEIGHT);
             if ($imginfo['width'] <= $imginfo['height']) {
                 $_image->resizeXY($width, 0);
             } elseif ($imginfo['width'] / $imginfo['height'] < $rate) {
                 $_image->resizeXY($width, 0);
             } elseif ($imginfo['width'] / $imginfo['height'] >= $rate) {
                 $_image->resizeXY(0, $height);
             }
             $_image->cropFromCenter($width, $height);
             $_image->save(NV_ROOTDIR . '/' . NV_TEMP_DIR, $basename);
             if (file_exists(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . $basename)) {
                 $imgsource = NV_BASE_SITEURL . NV_TEMP_DIR . '/' . $basename;
             }
         }
     } elseif (nv_is_url($homeimgfile)) {
         $imgsource = $homeimgfile;
     } else {
         $imgsource = '';
     }
     return $imgsource;
 }