public function save($con = null) { if (!file_exists(sfConfig::get('sf_upload_dir') . '/sfCart/products/')) { mkdir(sfConfig::get('sf_upload_dir') . '/sfCart/products/'); } $return = parent::save($con); $fullpath = $this->getValue('photo_path'); $genFileName = basename($fullpath); $thumbpath1 = sfConfig::get('sf_upload_dir') . '/sfCart/products/48x48/' . $genFileName; $thumbpath2 = sfConfig::get('sf_upload_dir') . '/sfCart/products/172x129/' . $genFileName; $thumbpath3 = sfConfig::get('sf_upload_dir') . '/sfCart/products/300x200/' . $genFileName; if (!file_exists(sfConfig::get('sf_upload_dir') . '/sfCart/products/48x48/')) { mkdir(sfConfig::get('sf_upload_dir') . '/sfCart/products/48x48/'); } if (!file_exists(sfConfig::get('sf_upload_dir') . '/sfCart/products/172x129/')) { mkdir(sfConfig::get('sf_upload_dir') . '/sfCart/products/172x129/'); } if (!file_exists(sfConfig::get('sf_upload_dir') . '/sfCart/products/300x200/')) { mkdir(sfConfig::get('sf_upload_dir') . '/sfCart/products/300x200/'); } //not handling if file already exists if (file_exists($fullpath)) { $thumbnail = new Thumb(48, 48); $thumbnail->loadFile($fullpath); $thumbnail->cropImage(48, 48, $fullpath, $thumbpath1); $thumbnail = new Thumb(172, 129); $thumbnail->loadFile($fullpath); $thumbnail->cropImage(172, 129, $fullpath, $thumbpath2); $thumbnail = new Thumb(300, 200); $thumbnail->loadFile($fullpath); $thumbnail->cropImage(300, 200, $fullpath, $thumbpath3); } return $return; }
public function getThumbsDown($id) { try { $valid_ip = Thumb::where('ip', '=', Puskice::getIP())->where('object_type', '=', 5)->where('object_id', '=', $id)->first(); if ($valid_ip != null) { throw new Exception("Error valid IP", 1); } $news = News::findOrFail($id); $news->thumbs_down++; $news->save(); $thumb = new Thumb(); $thumb->ip = Puskice::getIP(); $thumb->object_id = $news->id; $thumb->object_type = 5; $thumb->save(); $thumbs = array(); if (Cookie::get('ps_thumbs')) { $cookie = Cookie::get('ps_thumbs'); $thumbs = unserialize($cookie); if (isset($thumbs['page'][$news->id])) { return Response::json(array('status' => 'fail', 'message' => __("Већ сте оценили ову вест"))); } } $thumbs['page'][$news->id] = 'down'; Cookie::queue('ps_thumbs', serialize($thumbs), 2628000); return Response::json(array('status' => 'success', 'message' => _("Ваш глас је забележен. Хвала на труду"), 'thumbsUp' => $news->thumbs_up, 'thumbsDown' => $news->thumbs_down)); } catch (Exception $e) { return Response::json(array('status' => 'fail', 'message' => _("Већ сте оценили ову страницу"))); } }
public function getThumbsDown($id) { try { $this->googleAnalytics('/comments/thumbs-down/' . $id); $valid_ip = Thumb::where('ip', '=', Puskice::getIP())->where('object_type', '=', 2)->where('object_id', '=', $id)->first(); if ($valid_ip != null) { throw new Exception("Error valid IP", 1); } $comment = Comment::findOrFail($id); $comment->thumbs_down++; $comment->save(); $thumb = new Thumb(); $thumb->ip = Puskice::getIP(); $thumb->object_id = $comment->id; $thumb->object_type = 2; $thumb->save(); $thumbs = array(); if (Cookie::get('ps_thumbs')) { $cookie = Cookie::get('ps_thumbs'); $thumbs = unserialize($cookie); if (isset($thumbs['comments'][$comment->id])) { return Response::json(array('status' => 'fail', 'message' => __("Већ сте оценили овај коментар"))); } } $thumbs['comments'][$comment->id] = 'down'; Cookie::queue('ps_thumbs', serialize($thumbs), 2628000); return Response::json(array('status' => 'success', 'message' => _("Ваш глас је забележен. Хвала на труду"), 'thumbsUp' => $comment->thumbs_up, 'thumbsDown' => $comment->thumbs_down)); } catch (Exception $e) { return Response::json(array('status' => 'fail', 'message' => _("Већ сте оценили овај коментар"))); } }
public function action_bmp() { $source = '128919316276.jpg'; $thumb = new Thumb(); $thumb->create($source, 130, 130); // $img = $thumb->imagecreatefrombmp($source); $this->auto_render = false; }
public function action_index() { $group = $this->request->param('group'); if (!$group) { throw new HTTP_Exception_404(); } $config = Kohana::$config->load('thumb')->get($group); if (!$config) { throw new HTTP_Exception_404(); } $file = $this->request->param('file'); if (!$file) { throw new HTTP_Exception_404(); } $path = Arr::get($config, 'path', ''); if (!empty($path)) { $path = rtrim($path, '/') . '/'; } $thumb = Thumb::create($group, $path . $file); if ($thumb) { // Get the extension from the filename $ext = strtolower(pathinfo($thumb, PATHINFO_EXTENSION)); $mime = File::mime_by_ext($ext); $this->response->headers('Content-Type', $mime ? $mime : 'image/jpeg'); $this->response->body(file_get_contents($thumb)); } else { throw new HTTP_Exception_500(); } }
function upload_post_main_image($data) { try { $cover_sizes = array(array(150, 150, false), array(400, 400, true)); $content = $data['text']; $urls = array(); preg_match_all("/(<img )(.+?)( \\/)?(>)/", $content, $images); foreach ($images[2] as $val) { if (preg_match("/(src=)('|\")(.+?)('|\")/", $val, $matches) == 1) { $urls[$matches[3]] = $matches[3]; } } if (count($urls)) { foreach ($urls as $url) { $imgdata = grab($url); $tmp_name = '/tmp/image.jpg'; file_put_contents($tmp_name, $imgdata); $size = getimagesize($tmp_name); if ($size) { if ($size[0] >= 150) { if ($size[1] >= 150) { $folder = Config::need('static_path') . 'upload/post_images/' . $data['id']; $filename = $folder . '/' . $data['id'] . '_' . $data['id_author'] . '.jpg'; $filename_o = $folder . '/' . $data['id'] . '_' . $data['id_author'] . '_big.jpg'; mkdir($folder); $thumb = new Thumb(); try { $thumb->createThumbnails($tmp_name, array($filename, $filename_o), $cover_sizes); } catch (Exception $e) { return false; } unlink($tmp_name); return true; } } } else { unlink($tmp_name); } } } return false; } catch (Exception $e) { return false; } }
/** * 控制器方法执行前的操作 * */ public function before() { parent::before(); if (!($this->dir = $this->request->directory)) { $this->dir = 'default'; } else { $this->dir = $this->request->directory; $this->template_dir = $this->request->directory; } if (!($this->ctrl = $this->request->controller)) { $this->ctrl = 'index'; } if (!($this->act = $this->request->action)) { $this->act = 'index'; } /* 初始化模板对象 */ $this->template = new View(); $this->template->script = ''; $this->template->css = ''; $this->template->directory = $this->dir; $this->template->controller = $this->ctrl; $this->template->action = $this->act; //缩略图 $this->template->thumb = $this->thumb = Thumb::getInstance(); /* 判断是否已登录 */ $this->template->auth = $this->auth = Session::instance()->get('user', false); $this->template->auth_field = $this->auth_field = isset($this->auth['field']) ? $this->auth['field'] : array(); $sys_configs = Cache::instance()->get('sys_configs'); if (null == $sys_configs) { $sys_configs = ORM::factory('user')->setConfig(); } $this->template->configs = $this->configs = $sys_configs; /* xss过滤 */ if (!empty($_POST)) { $_POST = Security::xss_clean($_POST); } if (!empty($_GET)) { $_GET = Security::xss_clean($_GET); } }
function Upload($file, $path, $codificar = null) { $uploadDir = INTERNAL_ROOT_PORTAL . '/' . $path; //Verificar se tem que renomear o arquivo if ($codificar == null) { $name = $file['name']; $uploadFile = $uploadDir . $name; $extension = pathinfo($file['name'], PATHINFO_EXTENSION); } else { $name = sha1(date("d-m-Y H:i:s")); $uploadFile = $uploadDir . $name; $extension = pathinfo($file['name'], PATHINFO_EXTENSION); $uploadFile = $uploadFile . '.' . $extension; $name .= '.' . $extension; } //Fazer o Upload do arquivo if (move_uploaded_file($file['tmp_name'], $uploadFile)) { $tipos = array("jpg", 'jpeg', 'png', 'gif'); if (in_array($extension, $tipos)) { $resizeObj = new Thumb($uploadFile); $resizeObj->resizeImage(64, 64); $resizeObj->saveImage($uploadDir . '/thumb/' . $name, 100); } $data['error'] = 0; $data['name'] = $name; } else { $data['error'] = 1; $data['name'] = NULL; } return $data; }
/** * Create image thumbnails * If coordinates are not set, $entity metadata will be used * * @param ElggEntity $entity Entity * @param int $x1 Upper left crooping coordinate * @param int $y1 Upper left crooping coordinate * @param int $x2 Lower right cropping coordinate * @param int $y2 Lower right cropping coordinate * @return Thumb[]|false */ public function createThumbs(ElggEntity $entity, $x1 = null, $y1 = null, $x2 = null, $y2 = null) { if (!$this->isImage($entity)) { return false; } $this->clearThumbs($entity); $x1 = isset($x1) ? (int) $x1 : (int) $entity->x1; $y1 = isset($y1) ? (int) $y1 : (int) $entity->y1; $x2 = isset($x2) ? (int) $x2 : (int) $entity->x2; $y2 = isset($y2) ? (int) $y2 : (int) $entity->y2; $crop_width = $x2 - $x1; $crop_height = $y2 - $y1; $error = false; $thumbs = []; $sizes = $this->getThumbSizes($entity); foreach ($sizes as $size => $opts) { $width = elgg_extract('w', $opts); $height = elgg_extract('h', $opts); $square = elgg_extract('square', $opts); $croppable = elgg_extract('croppable', $opts, $square); $mode = elgg_extract('mode', $opts); $metadata_name = elgg_extract('metadata_name', $opts); if ($metadata_name && $entity->{$metadata_name}) { $filestorename = $entity->{$metadata_name}; } else { $directory = $this->getThumbDirectory($entity); $filename = $this->getThumbFilename($entity, $size); $filestorename = "{$directory}/{$filename}"; } $thumb = new Thumb(); $thumb->owner_guid = $entity->owner_guid; $thumb->setFilename($filestorename); if (!$thumb->exists()) { $thumb->open('write'); $thumb->close(); } $thumbs[] = $thumb; $params = ['entity' => $entity, 'thumb' => $thumb]; $options = elgg_trigger_plugin_hook('options', 'imagine', $params, []); try { ini_set('memory_limit', '256M'); if ($mode != 'outbound' && $mode != 'inset') { $mode = $square ? 'outbound' : 'inset'; } $box = new Box($width, $height); $image = $this->imagine->open($entity->getFilenameOnFilestore()); if ($croppable && $crop_width > 0 && $crop_height > 0) { $image = $image->crop(new Point($x1, $y1), new Box($crop_width, $crop_height)); } $image = $image->thumbnail($box, $mode); $image->save($thumb->getFilenameOnFilestore(), $options); unset($image); if (!empty($opts['metadata_name'])) { $md_name = $opts['metadata_name']; $entity->{$md_name} = $thumb->getFilename(); } } catch (Exception $ex) { elgg_log($ex->getMessage(), 'ERROR'); $error = true; } } if ($error) { foreach ($thumbs as $thumb) { $thumb->delete(); } return false; } $entity->icon_owner_guid = $entity->owner_guid; return $thumbs; }
break; } if ($bio['foaf:img']) { $pic = 0; $imgdata = grab($bio['foaf:img']); $tmp_name = '/tmp/aimage.jpg'; file_put_contents($tmp_name, $imgdata); $size = getimagesize($tmp_name); if ($size) { if ($size[0] >= 10) { if ($size[1] >= 10) { $folder = Config::need('static_path') . 'upload/author_images/' . ceil($author['id'] / 500); $filename = $folder . '/' . $author['id'] . '.jpg'; $filename1 = $folder . '/' . $author['id'] . '_small.jpg'; mkdir($folder); $thumb = new Thumb(); try { $thumb->createThumbnails($tmp_name, array($filename, $filename1), $cover_sizes); $pic = 1; } catch (Exception $e) { continue; } unlink($tmp_name); } } } else { unlink($tmp_name); } } else { $pic = 0; }
if (empty($_row['link'])) { $_t = '<span>' . HTML::chars($_row['title']) . '</span>'; } else { $_t = HTML::anchor($_row['link'], $_row['title']); } $_list[] = '<li class="' . $_c . '">' . $_t . '</li>'; } $_body = '<ul>' . implode('', $_list) . '</ul>'; break; case 'image': $li_class = 'one-fourth-column hidden-on-mobile'; if (empty($_column['image'])) { $_thumb = Thumb::uri('width_267_no_img', $NO_IMG); } else { $_src = $orm_helper->file_uri('image', $_column['image']); $_thumb = Thumb::uri('width_267', $_src); } $_img = HTML::image($_thumb, array('alt' => $_column['title'])); $_descr = empty($_column['description']) ? '' : '<span>' . $_column['description'] . '</span>'; $_body = ' <figure> ' . $_img . ' <figcaption> <h3>' . HTML::chars($_column['title']) . '</h3> ' . HTML::chars($_descr) . ' </figcaption> </figure> '; if (!empty($_row['link'])) { $_body = HTML::anchor($_row['link'], $_body, array('class' => 'img-caption margin-reset')); } else {
<?php defined('SYSPATH') or die('No direct script access.'); if (empty($list)) { return; } ?> <div class="slider-padding"> <div id="product-slider-vertical" class="royalSlider rsDefault"> <?php $tpl = ' <a href="{SRC_BIG}" class="mfp-gallery" title="{TITLE}"> <img class="rsImg" src="{SRC_NORMAL}" data-rsTmb="{SRC_SMALL}" alt="{TITLE}" /> </a> '; $url_base = URL::base(); foreach ($list as $_item) { $_thumb_small = $url_base . Thumb::uri('list_96x105', $_item['src']); $_thumb_normal = $url_base . Thumb::uri('list_560x632', $_item['src']); $_thumb_big = $url_base . Thumb::uri('list_1024x768', $_item['src']); echo str_replace(array('{SRC_BIG}', '{SRC_NORMAL}', '{SRC_SMALL}', '{TITLE}'), array($_thumb_big, $_thumb_normal, $_thumb_small, $_item['title']), $tpl); } ?> </div> <div class="clearfix"></div> </div> <script type="text/javascript"> s.initList.push('initProductSlider'); </script>
<?php defined('SYSPATH') or die('No direct script access.'); $list_tpl = URL::base() . Page_Route::uri($PAGE_ID, 'catalog', array('category_uri' => $CATEGORY->uri)); /* * FIXME $list_tpl */ $orm_helper = ORM_Helper::factory('catalog_Category'); foreach ($list_categories as $_orm) { $_link = $list_tpl . '/' . $_orm->uri; if (!empty($_orm->image)) { $_src = $orm_helper->file_uri('image', $_orm->image); $_thumb = Thumb::uri('list_420x420', $_src); } else { $_thumb = Thumb::uri('list_420x420_no_img', $NO_IMG); } ?> <div class="four columns"> <a href="<?php echo $_link; ?> " class="img-caption" > <figure> <?php echo HTML::image($_thumb, array('alt' => $_orm->title)); ?> <figcaption> <h3><?php echo HTML::chars($_orm->title);
function thumb_generate($img, $width, $height, $def_img = false, $type_resize = 'resize_full_crop_center', $replace_file = false, $subdir = 'mini', $postfix = true) { // указана картинка, нужно сделать thumb заданного размера if ($img) { // если true, то делаем из ширину+высоту // если false, то постфикса не будет if ($postfix === true) { $postfix = '-' . $width . '-' . $height; } $t = new Thumb($img, $postfix, $replace_file, $subdir); if ($t->init === true) { $img = $t->new_img; // сразу получаем новый адрес } elseif ($t->init === false) { // $img = false; // ошибка $img = $def_img; // ставим дефолтное изображение } else { // получаем изображение if ($type_resize == 'resize_crop') { $t->resize_crop($width, $height); } elseif ($type_resize == 'crop_center') { $t->crop_center($width, $height); } elseif ($type_resize == 'crop') { $t->crop($width, $height); } elseif ($type_resize == 'resize') { $t->resize($width, $height); } elseif ($type_resize == 'resize_h_crop_center') { $t->resize_h_crop_center($width, $height); } elseif ($type_resize == 'resize_crop_center') { $t->resize_crop_center($width, $height); } else { $t->resize_full_crop_center($width, $height); } $img = $t->new_img; // url-адрес готового изображения } } else { $img = $def_img; } return $img; }
function write() { global $current_user; /* @var $current_user CurrentUser */ $mask = array('id' => 'int', 'nickname' => array('type' => 'string', 'regexp' => '/^[A-Za-z][A-Za-z0-9_]+$/', 'min_length' => 3, 'max_length' => 26, '*' => true), 'role' => array('type' => 'int', '*' => true), 'link_fb' => array('type' => 'string', '*' => true), 'link_vk' => array('type' => 'string', '*' => true), 'link_lj' => array('type' => 'string', '*' => true), 'link_tw' => array('type' => 'string', '*' => true), 'quote' => array('type' => 'string', '*' => true), 'about' => array('type' => 'string', '*' => true)); $params = Request::checkPostParameters($mask); $uid = isset($params['id']) ? $params['id'] : 0; if (!$uid) { throw new Exception('illegal user id'); } if ($current_user->id != $params['id']) { if ($current_user->getRole() >= User::ROLE_BIBER) { $editing_user = Users::getByIdsLoaded(array($params['id'])); $editing_user = isset($editing_user[$params['id']]) ? $editing_user[$params['id']] : false; } } else { $editing_user = $current_user; } $current_user->can_throw('users_edit', $editing_user); if ($editing_user) { if (trim($params['nickname']) != $editing_user->getNickName()) { if (!$editing_user->checkNickChanging()) { throw new Exception('You can\'t change your nickname'); } } //avatar if (isset($_FILES['picture']) && $_FILES['picture']['tmp_name']) { $filename = Config::need('avatar_upload_path') . '/' . $editing_user->id . '.jpg'; $folder = Config::need('avatar_upload_path'); $filename_normal = $folder . '/default_' . $editing_user->id . '.jpg'; $filename_small = $folder . '/small_' . $editing_user->id . '.jpg'; $filename_big = $folder . '/big_' . $editing_user->id . '.jpg'; $filename_orig = $folder . '/orig_' . $editing_user->id . '.jpg'; $thumb = new Thumb(); $thumb->createThumbnails($_FILES['picture']['tmp_name'], array($filename_small, $filename_normal, $filename_big, $filename_orig), self::$cover_sizes); $editing_user->setProperty('picture', 1); $editing_user->setProperty('lastSave', time()); } if ($editing_user->getRole() < User::ROLE_SITE_ADMIN) { if ($current_user->getRole() == User::ROLE_BIBER) { if (($new_role = (int) $params['role']) !== false) { foreach (Users::$rolenames as $id => $name) { if ($id == $new_role) { if ($new_role < User::ROLE_SITE_ADMIN) { $editing_user->setRole($new_role); } } } } } if ($current_user->getRole() > User::ROLE_BIBER) { if (($new_role = (int) $params['role']) !== false) { foreach (Users::$rolenames as $id => $name) { if ($id == $new_role) { if ($new_role <= User::ROLE_SITE_ADMIN) { $editing_user->setRole($new_role); } } } } } } $editing_user->save(); // после редактирования профиля надо посбрасывать кеш со страницы профиля // и со страницы редактирования профиля // кеш в остальных модулях истечет сам Users::dropCache($editing_user->id); } else { Error::CheckThrowAuth(User::ROLE_SITE_ADMIN); } }
<?php $orm_helper = ORM_Helper::factory('news'); foreach ($list as $_orm) { $cat_orm = Arr::get($categories, $_orm->category_id); if (empty($cat_orm)) { continue; } $_public_ts = strtotime($_orm->public_date); $_link = str_replace(array('{category_uri}', '{uri}', '{id}'), array($cat_orm->uri, $_orm->uri, $_orm->id), $detail_tpl); ?> <article class="post"> <?php if (!empty($_orm->image)) { $_src = $orm_helper->file_uri('image', $_orm->image); $_thumb = Thumb::uri('news_860', $_src); ?> <figure class="post-img"> <a href="<?php echo $_link; ?> "> <?php echo HTML::image($_thumb, array('alt' => $_orm->title, 'title' => $_orm->title)); ?> </a> </figure> <?php }
/** * @brief 把cookie的结构转化成为程序所用的数据结构 * @param $cartValue 购物车cookie存储结构 * @return array : [goods]=>array( ['id']=>商品ID , ['data'] => array( [商品ID]=>array ([name]商品名称 , [img]图片地址 , [sell_price]价格, [count]购物车中此商品的数量 ,[type]类型goods,product , [goods_id]商品ID值 ) ) ) , [product]=>array( 同上 ) , [count]购物车商品和货品数量 , [sum]商品和货品总额 ; */ private function cartFormat($cartValue) { //初始化结果 $result = $this->cartExeStruct; $goodsIdArray = array(); if (isset($cartValue['goods']) && $cartValue['goods']) { $goodsIdArray = array_keys($cartValue['goods']); $result['goods']['id'] = $goodsIdArray; foreach ($goodsIdArray as $gid) { $result['goods']['data'][$gid] = array('id' => $gid, 'type' => 'goods', 'goods_id' => $gid, 'count' => $cartValue['goods'][$gid]); //购物车中的种类数量累加 $result['count'] += $cartValue['goods'][$gid]; } } if (isset($cartValue['product']) && $cartValue['product']) { $productIdArray = array_keys($cartValue['product']); $result['product']['id'] = $productIdArray; $productObj = new IModel('products'); $productData = $productObj->query('id in (' . join(",", $productIdArray) . ')', 'id,goods_id,sell_price'); foreach ($productData as $proVal) { $result['product']['data'][$proVal['id']] = array('id' => $proVal['id'], 'type' => 'product', 'goods_id' => $proVal['goods_id'], 'count' => $cartValue['product'][$proVal['id']], 'sell_price' => $proVal['sell_price']); if (!in_array($proVal['goods_id'], $goodsIdArray)) { $goodsIdArray[] = $proVal['goods_id']; } //购物车中的种类数量累加 $result['count'] += $cartValue['product'][$proVal['id']]; } } if ($goodsIdArray) { $goodsArray = array(); $goodsObj = new IModel('goods'); $goodsData = $goodsObj->query('id in (' . join(",", $goodsIdArray) . ')', 'id,name,img,sell_price'); foreach ($goodsData as $goodsVal) { $goodsArray[$goodsVal['id']] = $goodsVal; } foreach ($result['goods']['data'] as $key => $val) { $result['goods']['data'][$key]['img'] = Thumb::get($goodsArray[$val['goods_id']]['img'], 120, 120); $result['goods']['data'][$key]['name'] = $goodsArray[$val['goods_id']]['name']; $result['goods']['data'][$key]['sell_price'] = $goodsArray[$val['goods_id']]['sell_price']; //购物车中的金额累加 $result['sum'] += $goodsArray[$val['goods_id']]['sell_price'] * $val['count']; } foreach ($result['product']['data'] as $key => $val) { $result['product']['data'][$key]['img'] = Thumb::get($goodsArray[$val['goods_id']]['img'], 120, 120); $result['product']['data'][$key]['name'] = $goodsArray[$val['goods_id']]['name']; //购物车中的金额累加 $result['sum'] += $result['product']['data'][$key]['sell_price'] * $val['count']; } } return $result; }
function thumb_generate($img, $width, $height, $def_img = false, $replace_file = false) { // указана картинка, нужно сделать thumb заданного размера if ($img) { $t = new Thumb($img, '-' . $width . '-' . $height, $replace_file); if ($t->init === true) { $img = $t->new_img; // сразу получаем новый адрес } elseif ($t->init === false) { $img = false; // ошибка } else { // получаем изображение // уменьшение по ширине, после кроп по центру $t->resize_crop_сenter($width, $height); $img = $t->new_img; // url-адрес готового изображения } } else { $img = $def_img; } return $img; }
/** * 编辑图片 */ public function action_picedit() { $this->checklogin(); $this->template->pid = $pid = (int) $this->getRequest('pid'); $this->template->zoom = $zoom = trim($this->getQuery('zoom')); $this->template->info = $info = ORM::factory('img')->where('imgs.userid', '=', (int) $this->auth['uid'])->where('imgs.id', '=', $pid)->find(); if (empty($info->picname)) { $this->show_message('非法访问', 0, array(), true); } $url = "http://" . $info->disk_id . '.wal8.com/'; $picname = $info->disk_name . '/' . $info->picname; $thumb = new Thumb(); if ($zoom == 'medium') { $picname = $thumb->create($picname, 640, 640, 's'); } elseif ($zoom == 'thumb') { $picname = $thumb->create($picname, 130, 130); } $this->template->picname = $url . $picname; if ($this->isPost()) { $editName = trim($this->getPost('name')); $pid = (int) $this->getPost('pid'); $set['custom_name'] = $editName; if (!empty($_FILES['newfile']['name'])) { $disks = ORM::factory('img_disk')->where('is_use', '=', 1)->find(); $save_dir = ORM::factory('user', (int) $this->auth['uid'])->save_dir; $savePath = DOCROOT . '' . $disks->disk_name . '/' . $save_dir . '/'; $upload = new Upload(array('size' => 2024)); try { $upload->set_path($savePath); $result = $upload->save($_FILES['newfile']); //$set['picname'] = $result['saveName']; $set['filename'] = $result['name']; $set['custom_name'] = $result['name']; $set['filesize'] = $result['size']; $picPath = pathinfo($info->disk_name . '/' . $info->picname); $img_dir = '/s/'; $img_dir2 = '/thumbnails/'; if (!empty($this->img_size)) { foreach ($this->img_size as $key => $v) { //标准图路径 $zoomPath = $picPath['dirname'] . $img_dir . $picPath['filename'] . $v; @unlink(Io::strip(DOCROOT . $zoomPath . $picPath['extension'])); @unlink(Io::strip(DOCROOT . $zoomPath . 'jpg')); //缩略图路径 $thumbPath = $info->disk_name . $img_dir2 . $picPath['filename'] . $v; @unlink(Io::strip(DOCROOT . $thumbPath . $picPath['extension'])); @unlink(Io::strip(DOCROOT . $thumbPath . 'jpg')); @unlink(Io::strip(DOCROOT . $thumbPath . 'gif')); } @unlink(Io::strip(DOCROOT . $info->disk_name . '/' . $info->picname)); $saveName = $disks->disk_name . '/' . $save_dir . '/' . $result['saveName']; rename($saveName, DOCROOT . $info->disk_name . '/' . $info->picname); $saveName = $disks->disk_name . '/' . $save_dir . '/' . $info->picname; $url = 'http://' . $info->disk_id . '.wal8.com/'; $data = array('img_url' => $url . $this->thumb->create($saveName, 130, 130), 'add_time' => time(), 'uid' => $this->auth['uid']); $this->squid_img($data); $data['img_url'] = $url . $this->thumb->create($saveName, 640, 640, 's'); $this->squid_img($data); $data['img_url'] = $url . $this->thumb->create($saveName, 120, 120); $this->squid_img($data); $data['img_url'] = $url . $saveName; $this->squid_img($data); } } catch (Exception $e) { $this->show_message($e->getMessage(), 0, array(), true); } } DB::update('imgs')->set($set)->where('id', '=', $pid)->execute(); $sum = DB::select(DB::expr("sum(filesize) as sums"))->from('imgs')->where('userid', '=', $this->auth['uid'])->execute()->get('sums'); DB::update('users')->set(array('use_space' => $sum))->where('uid', '=', $this->auth['uid'])->execute(); ORM::factory('user')->upcache($this->auth['uid']); $links[] = array('text' => '重载图片编辑', 'href' => '/pic/picedit?pid=' . $pid); $this->show_message('修改图片处理成功', 1, $links, true); } }
/** * @brief 生成$fileName文件的缩略图,位置与$fileName相同 * @param string $fileName 要生成缩略图的目标文件 * @param int $width 缩略图宽度 * @param int $height 缩略图高度 * @param string $extName 缩略图文件名附加值 * @param string $saveDir 缩略图存储目录 */ public static function thumb($fileName, $width, $height, $extName = '_thumb', $saveDir = '') { return Thumb::get($fileName, $width, $height); }
var goodsSmallPic = "<?php echo IUrl::creatUrl("") . "views/" . $this->theme . "/skin/" . $this->skin . "/images/front/nopic_435_435.gif"; ?> "; var goodsBigPic = "<?php echo IUrl::creatUrl("") . "views/" . $this->theme . "/skin/" . $this->skin . "/images/front/nopic_435_435.gif"; ?> "; //存在图片数据时候 <?php if (isset($photo) && $photo) { ?> goodsSmallPic = "<?php echo IUrl::creatUrl("") . ""; echo Thumb::get($photo[0]['img'], 435, 435); ?> "; goodsBigPic = "<?php echo IUrl::creatUrl("") . ""; echo isset($photo[0]['img']) ? $photo[0]['img'] : ""; ?> "; <?php } ?> //初始化商品轮换图 var bxObj = $('#thumblist').bxSlider({ infiniteLoop: false, hideControlOnEnd: true,
private function on_getThumbHref() { json_fail(1, "thumbnails disabled", !$this->options["thumbnails"]["enabled"]); json_fail(2, "thumbnails not supported", !HAS_PHP_JPG); $type = use_request_param("type"); $src_url = use_request_param("href"); $mode = use_request_param("mode"); $width = use_request_param("width"); $height = use_request_param("height"); $thumb = new Thumb($this->app); $thumb_url = $thumb->thumb($type, $src_url, $mode, $width, $height); json_fail(3, "thumbnail creation failed", $thumb_url === null); json_exit(array("absHref" => $thumb_url)); }
<?php defined('SYSPATH') or die('No direct script access.'); $thumb = NULL; if (!empty($orm->image_1)) { $src = ORM_Helper::factory('catalog_Element')->file_uri('image_1', $orm->image_1); $thumb = Thumb::uri('list_80x80', $src); unset($src); } if (empty($thumb) and !empty($orm->image_2)) { $src = ORM_Helper::factory('catalog_Element')->file_uri('image_2', $orm->image_2); $thumb = Thumb::uri('list_80x80', $src); unset($src); } if (empty($thumb)) { $thumb = Thumb::uri('list_80x80_no_img', $NO_IMG); } $nom_item = reset($nomenclature); $currency = 'руб.'; ?> <section class="relative"> <?php echo HTML::anchor('#size-select', __('Choose size'), array('class' => 'button dark popup-with-size-select')); ?> <span class="product-price js-render-field"> <?php if (!empty($nom_item['price'])) { echo HTML::chars($nom_item['price'] . ' ' . $currency); } ?>
/** * Shortcut to create a new thumb object * * @param mixed Either a file path or a Media object * @param array An array of additional params for the thumb * @return object Thumb */ function thumb($image, $params = array(), $obj = true) { if (is_a($image, 'File') || is_a($image, 'Asset')) { return $obj ? $image->thumb($params) : $image->thumb($params)->url(); } else { $class = new Thumb($image, $params); return $obj ? $class : $class->url(); } }
<?php defined('SYSPATH') or die('No direct script access.'); if ($value) { $img_size = getimagesize(DOCROOT . $orm_helper->file_path($field, $value)); $src = $orm_helper->file_uri($field, $value); if ($img_size[0] > 100 or $img_size[1] > 100) { $thumb = Thumb::uri('admin_image_100', $src); } else { $thumb = $src; } echo HTML::anchor($src, HTML::image($thumb), array('class' => 'image-holder')); } else { echo __('No image'); }
function write() { global $current_user; $current_user->can_throw('books_edit'); $id = isset(Request::$post['id']) ? (int) Request::$post['id'] : false; if (!$id) { $this->newAuthor(); return; } $person = Persons::getInstance()->getByIdLoaded($id); if (!$person) { return; } $savedData = $person->data; /* @var $book Book */ $fields = array('lang_code' => 'author_lang', 'bio' => 'bio', 'first_name' => 'first_name', 'middle_name' => 'middle_name', 'last_name' => 'last_name', 'homepage' => 'homepage', 'wiki_url' => 'wiki_url', 'date_birth' => 'date_birth', 'date_death' => 'date_death'); if (!Request::$post['first_name'] || !Request::$post['last_name']) { throw new Exception('no author\'s name'); } if (!Request::$post['lang_code']) { throw new Exception('no author\'s language'); } Request::$post['lang_code'] = Config::$langs[Request::$post['lang_code']]; $to_update = array(); if (isset($_FILES['picture']) && $_FILES['picture']['tmp_name']) { $folder = Config::need('static_path') . '/upload/authors/' . ceil($person->id / 5000); @mkdir($folder); // inserting new cover $query = 'INSERT INTO `person_covers` SET `id_person`=' . $person->id; Database::query($query); $cover_id = Database::lastInsertId(); // generating file names $filename_normal = $folder . '/default_' . $person->id . '_' . $cover_id . '.jpg'; $filename_small = $folder . '/small_' . $person->id . '_' . $cover_id . '.jpg'; $filename_big = $folder . '/big_' . $person->id . '_' . $cover_id . '.jpg'; $filename_orig = $folder . '/orig_' . $person->id . '_' . $cover_id . '.jpg'; $to_update['has_cover'] = $cover_id; $thumb = new Thumb(); $thumb->createThumbnails($_FILES['picture']['tmp_name'], array($filename_small, $filename_normal, $filename_big, $filename_orig), self::$cover_sizes); if ($savedData['has_cover']) { $current_user->gainActionPoints('authors_add_cover', $person->id, BiberLog::TargetType_person); } else { $current_user->gainActionPoints('authors_edit_cover', $person->id, BiberLog::TargetType_person); } } foreach ($fields as $field => $personfield) { if (!isset(Request::$post[$field])) { throw new Exception('field missed #' . $field); } if ($person->data[$personfield] != Request::$post[$field]) { $to_update[$personfield] = Request::$post[$field]; } } $q = array(); if (count($to_update)) { $to_update['authorlastSave'] = time(); } foreach ($to_update as $field => &$value) { if ($field == 'date_birth' || $field == 'date_death') { $value = getDateFromString($value); } if ($field == 'bio') { list($full, $short) = $person->processBio($value); $q[] = '`bio`=' . Database::escape($full) . ''; $q[] = '`short_bio`=' . Database::escape($short) . ''; $value = $person->data['bio'] = $full; $person->data['short_bio'] = $short; } else { $q[] = '`' . $field . '`=' . Database::escape($value) . ''; $person->data[$field] = $value; } } if (count($q)) { $query = 'UPDATE `persons` SET ' . implode(',', $q) . ' WHERE `id`=' . $person->id; Database::query($query); unset($to_update['authorlastSave']); PersonLog::addLog($to_update, $savedData, $person->id); PersonLog::saveLog($person->id, BiberLog::TargetType_person, $current_user->id, BiberLog::BiberLogType_personEdit); Persons::getInstance()->dropCache($person->id); $current_user->gainActionPoints(BiberLog::$actionTypes[BiberLog::BiberLogType_personEdit], $person->id, BiberLog::TargetType_person); $search = Search::getInstance(); /* @var $search Search */ $search->setAuthorToFullUpdate($person->id); } ob_end_clean(); header('Location:' . Config::need('www_path') . '/a/' . $person->id); exit; }
$detail_tpl = URL::base() . Page_Route::uri($page['id'], 'catalog_element', array('element_uri' => '{ELEMENT_URI}', 'element_id' => '{ELEMENT_ID}')); $orm_helper = ORM_Helper::factory('catalog_Element'); foreach ($list as $_orm) { $_link = str_replace(array('{ELEMENT_URI}', '{ELEMENT_ID}'), array($_orm->uri, $_orm->id), $detail_tpl); $_thumb_1 = NULL; if (!empty($_orm->image_1)) { $_src = $orm_helper->file_uri('image_1', $_orm->image_1); $_thumb_1 = Thumb::uri('list_420x535', $_src); unset($_src); } else { $_thumb_1 = Thumb::uri('list_420x535_no_img', $NO_IMG); } $_thumb_2 = NULL; if (!empty($_orm->image_2)) { $_src = $orm_helper->file_uri('image_2', $_orm->image_2); $_thumb_2 = Thumb::uri('list_420x535', $_src); unset($_src); } $_class = empty($_thumb_2) ? 'transform-clear' : ''; ?> <div class="four shop columns"> <figure class="product <?php echo $_class; ?> "> <div class="mediaholder"> <a href="<?php echo $_link; ?> ">
/** * Generate the thumbnail * * @access public * @return void **/ public function index() { return parent::index('SCALE'); }
/** * Shortcut to create a new thumb object * * @param mixed Either a file path or a Media object * @param array An array of additional params for the thumb * @return object Thumb */ function thumb($image, $params = array(), $obj = true) { $class = new Thumb($image, $params); return $obj ? $class : $class->url(); }
function MakeThumbs() { global $CMS; $TH = new Thumb(); if ($this->IsAvatars()) { // ** This is the output file ** // $strThumbNoExt = $this->GetFileNameWithoutExtension($this->strFileFullPath); $strExtension = $this->GetExtensionFromPath($this->strFileFullPath); $intAvatarSize = $CMS->SYS->GetSysPref(C_PREF_AVATAR_SIZE); $strThumbAvatar = $strThumbNoExt . "_t1." . $strExtension; // ** We only need relative paths for the database ** // $this->strDBAvatarThumb = $this->strSiteDir . $this->GetFileNameFromPath($strThumbAvatar); if (!$TH->Make($this->strFileFullPath, $strThumbAvatar, $intAvatarSize)) { $this->strDBAvatarThumb = ""; } @($blnFile = unlink($this->GetFileFullPath())); if (!$blnFile) { if (file_exists($this->strFileFullPath) == true) { $this->strWarnings .= M_ERR_UPLOAD_NOT_DELETED_ACCESS . "(" . $this->strFileFullPath . ")"; } else { $this->strWarnings .= M_ERR_UPLOAD_NOT_DELETED_MISSING . "(" . $this->strFileFullPath . ")"; } } } else { // ** These are the output files ** // $strThumbNoExt = $this->GetFileNameWithoutExtension($this->strFileFullPath); $strExtension = $this->GetExtensionFromPath($this->strFileFullPath); $intThumbSmall = $CMS->SYS->GetSysPref(C_PREF_THUMB_SMALL); $intThumbMedium = $CMS->SYS->GetSysPref(C_PREF_THUMB_MEDIUM); $intThumbLarge = $CMS->SYS->GetSysPref(C_PREF_THUMB_LARGE); $strThumbSmall = $strThumbNoExt . "_t1." . $strExtension; $strThumbMedium = $strThumbNoExt . "_t2." . $strExtension; $strThumbLarge = $strThumbNoExt . "_t3." . $strExtension; // ** We only need relative paths for the database ** // $this->strDBThumbSmall = $this->strSiteDir . $this->GetFileNameFromPath($strThumbSmall); $this->strDBThumbMedium = $this->strSiteDir . $this->GetFileNameFromPath($strThumbMedium); $this->strDBThumbLarge = $this->strSiteDir . $this->GetFileNameFromPath($strThumbLarge); if (!$TH->Make($this->strFileFullPath, $strThumbSmall, $intThumbSmall)) { $this->strDBThumbSmall = ""; } if (!$TH->Make($this->strFileFullPath, $strThumbMedium, $intThumbMedium)) { $this->strDBThumbMedium = ""; } if (!$TH->Make($this->strFileFullPath, $strThumbLarge, $intThumbLarge)) { $this->strDBThumbLarge = ""; } } }