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; }
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'); }
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 . '/'); } } }
/** * 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; }
function photos_thumbs($id, $file, $module_upload, $width = 270, $height = 210, $quality = 90) { if ($width >= $height) { $rate = $width / $height; } else { $rate = $height / $width; } $image = NV_UPLOADS_REAL_DIR . '/' . $module_upload . '/images/' . $file; if ($file != '' and file_exists($image)) { $imgsource = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module_upload . '/images/' . $file; $imginfo = nv_is_image($image); $basename = $module_upload . '_' . $width . 'x' . $height . '-' . $id . '-' . md5_file($image) . '.' . $imginfo['ext']; if (file_exists(NV_ROOTDIR . '/' . NV_UPLOADS_DIR . '/' . $module_upload . '/thumbs/' . $basename)) { $imgsource = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module_upload . '/thumbs/' . $basename; } else { $_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_UPLOADS_DIR . '/' . $module_upload . '/thumbs/', $basename, $quality); if (file_exists(NV_ROOTDIR . '/' . NV_UPLOADS_DIR . '/' . $module_upload . '/thumbs/' . $basename)) { $imgsource = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module_upload . '/thumbs/' . $basename; } } } elseif (nv_is_url($file)) { $imgsource = $file; } else { $imgsource = ''; } return $imgsource; }
<?php /** * @Project NUKEVIET 3.0 * @Author VINADES.,JSC (contact@vinades.vn) * @Copyright (C) 2010 VINADES.,JSC. All rights reserved * @Createdate 2-2-2010 12:55 */ if (!defined('NV_IS_FILE_ADMIN')) { die('Stop!!!'); } $path = htmlspecialchars(trim($nv_Request->get_string('path', 'post')), ENT_QUOTES); if ($admin_info['allow_modify_files'] && nv_check_allow_upload_dir($path)) { $imagename = htmlspecialchars(trim($nv_Request->get_string('img', 'post')), ENT_QUOTES); $width = $nv_Request->get_int('width', 'post'); $height = $nv_Request->get_int('height', 'post'); require_once NV_ROOTDIR . "/includes/class/image.class.php"; $image = new image(NV_ROOTDIR . '/' . $path . '/' . $imagename, NV_MAX_WIDTH, NV_MAX_HEIGHT); $image->resizeXY($width, $height); $new_imagename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $width . '_' . $height . '\\2', $imagename); $i = 1; while (file_exists(NV_ROOTDIR . '/' . $path . '/' . $new_imagename)) { $new_imagename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $width . '_' . $height . '_' . $i . '\\2', $imagename); $i++; } $image->save(NV_ROOTDIR . '/' . $path, $new_imagename, 75); //$image_info = $image->create_Image_info; $image->close(); echo $new_imagename; }
/** * * @param string $targetFilename * @param rectangle $rectangle * @return thumbnail */ protected function _getThumbnail($targetFilename, $rectangle) { $thumbnail = new image($targetFilename); $thumbnail->setType($this->getType()); $thumbnail->fromArea($this, $rectangle); $thumbnail->save(); return $thumbnail; }
public function crop_image($file, $size = '200') { $this->using('image'); $img = new image(); if ($img->load($file)) { $img->thumbnail($size); $img->save(); } }
function viewsubcat_main($viewcat, $array_cat) { global $module_name, $module_file, $global_array_cat, $lang_module, $module_config, $module_info, $global_config; $xtpl = new XTemplate($viewcat . '.tpl', NV_ROOTDIR . '/themes/' . $module_info['template'] . '/modules/' . $module_file); $xtpl->assign('LANG', $lang_module); $xtpl->assign('TEMPLATE', $global_config['module_theme']); // Hien thi cac chu de con foreach ($array_cat as $key => $array_row_i) { if (isset($array_cat[$key]['content'])) { $array_row_i['rss'] = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $module_info['alias']['rss'] . "/" . $array_row_i['alias']; $xtpl->assign('CAT', $array_row_i); $catid = intval($array_row_i['catid']); if ($array_row_i['subcatid'] != '') { $exl = 0; $arrsubcat_s = explode(',', $array_row_i['subcatid']); foreach ($arrsubcat_s as $subcatid_i) { if ($global_array_cat[$subcatid_i]['inhome'] == 1) { $xtpl->clear_autoreset(); if ($exl < 3) { $xtpl->assign('SUBCAT', $global_array_cat[$subcatid_i]); $xtpl->parse('main.listcat.subcatloop'); $xtpl->set_autoreset(); } else { $more = array('title' => $lang_module['more'], 'link' => $global_array_cat[$catid]['link']); $xtpl->assign('MORE', $more); $xtpl->parse('main.listcat.subcatmore'); $xtpl->set_autoreset(); break; } ++$exl; } } } $a = 0; $xtpl->assign('IMGWIDTH', $module_config[$module_name]['homewidth']); foreach ($array_cat[$key]['content'] as $array_row_i) { $newday = $array_row_i['publtime'] + 86400 * $array_row_i['newday']; $array_row_i['publtime'] = nv_date('d/m/Y h:i:s A', $array_row_i['publtime']); $array_row_i['hometext'] = nv_clean60($array_row_i['hometext'], 90); $array_row_i['title0'] = nv_clean60($array_row_i['title'], 40); ++$a; if ($a == 1) { $image = NV_UPLOADS_REAL_DIR . '/' . $module_name . '/' . $array_row_i['homeimgfile']; if ($array_row_i['homeimgfile'] != '' and file_exists($image)) { $width = 370; $height = 200; $array_row_i['imghome'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module_name . '/' . $array_row_i['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 . '_' . $array_row_i['id'] . '_\\1_' . $width . '-' . $height . '\\2', $basename); if (file_exists(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . $basename)) { $array_row_i['imghome'] = 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)) { $array_row_i['imghome'] = NV_BASE_SITEURL . NV_TEMP_DIR . '/' . $basename; } } } } if ($newday >= NV_CURRENTTIME) { $xtpl->parse('main.listcat.newday'); } $xtpl->assign('CONTENT', $array_row_i); if ($array_row_i['imghome'] != "") { $xtpl->assign('HOMEIMG', $array_row_i['imghome']); $xtpl->assign('HOMEIMGALT', !empty($array_row_i['homeimgalt']) ? $array_row_i['homeimgalt'] : $array_row_i['title']); $xtpl->parse('main.listcat.image'); } if (defined('NV_IS_MODADMIN')) { $xtpl->assign('ADMINLINK', nv_link_edit_page($array_row_i['id']) . " " . nv_link_delete_page($array_row_i['id'])); $xtpl->parse('main.listcat.adminlink'); } } else { if ($newday >= NV_CURRENTTIME) { $xtpl->assign('CLASS', 'icon_new_small'); } else { $xtpl->assign('CLASS', 'icon_list'); } $array_row_i['title0'] = nv_clean60($array_row_i['title'], 35); $array_row_i['hometext'] = nv_clean60($array_row_i['hometext'], 90); $xtpl->assign('OTHER', $array_row_i); $xtpl->parse('main.listcat.related.loop'); } if ($a > 1) { $xtpl->assign('WCT', 'col-md-8 '); } else { $xtpl->assign('WCT', ''); } $xtpl->set_autoreset(); } if ($a > 1) { $xtpl->parse('main.listcat.related'); } $xtpl->parse('main.listcat'); } } if ($module_config[$module_name]['showtooltip']) { $xtpl->assign('TOOLTIP_POSITION', $module_config[$module_name]['tooltip_position']); $xtpl->parse('main.tooltip'); } $xtpl->parse('main'); return $xtpl->text('main'); }
$upload_logo = NV_ROOTDIR . '/' . $global_config['site_logo']; } elseif (file_exists(NV_ROOTDIR . '/images/logo.png')) { $upload_logo = NV_ROOTDIR . '/images/logo.png'; } else { die('ERROR#' . $lang_module['notlogo']); } $config_logo = array(); $config_logo['x'] = $nv_Request->get_int('x', 'post', 0); $config_logo['y'] = $nv_Request->get_int('y', 'post', 0); $config_logo['w'] = $nv_Request->get_int('w', 'post', 0); $config_logo['h'] = $nv_Request->get_int('h', 'post', 0); if ($config_logo['w'] > 0 and $config_logo['h'] > 0) { require_once NV_ROOTDIR . '/includes/class/image.class.php'; $createImage = new image(NV_ROOTDIR . '/' . $path . '/' . $file, NV_MAX_WIDTH, NV_MAX_HEIGHT); $createImage->addlogo($upload_logo, '', '', $config_logo); $createImage->save(NV_ROOTDIR . '/' . $path, $file); $createImage->close(); if (isset($array_dirname[$path])) { if (preg_match('/^' . nv_preg_quote(NV_UPLOADS_DIR) . '\\/(([a-z0-9\\-\\_\\/]+\\/)*([a-z0-9\\-\\_\\.]+)(\\.(gif|jpg|jpeg|png)))$/i', $path . '/' . $file, $m)) { @nv_deletefile(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $m[1]); } $info = nv_getFileInfo($path, $file); $did = $array_dirname[$path]; $db->query("UPDATE " . NV_UPLOAD_GLOBALTABLE . "_file SET filesize=" . $info['filesize'] . ", src='" . $info['src'] . "', srcwidth=" . $info['srcwidth'] . ", srcheight=" . $info['srcheight'] . ", sizes='" . $info['size'] . "', userid=" . $admin_info['userid'] . ", mtime=" . $info['mtime'] . " WHERE did = " . $did . " AND title = '" . $file . "'"); } die('OK#' . basename($file)); } else { die('ERROR#' . $lang_module['notlevel']); } } die('ERROR#Error Access!!');
/** * nv_ImageInfo() * Function xuat ra cac thong tin ve IMAGE de dua vao HTML (src, width, height). * * @param mixed $original_name - duong dan tuyet doi den file goc (bat buoc) * @param integer $width - chieu rong xuat ra HTML (neu bang 0 se xuat ra kich thuoc thuc) * @param bool $is_create_thumb - Neu chieu rong cua hinh lon hon $width, co the tao thumbnail * @param string $thumb_path - neu tao thumbnail thi chi ra thu muc chua file thumbnail nay. * @return array('src','width','height') */ function nv_ImageInfo($original_name, $width = 0, $is_create_thumb = false, $thumb_path = '') { if (empty($original_name)) { return false; } $original_name = realpath($original_name); if (empty($original_name)) { return false; } $original_name = str_replace('\\', '/', $original_name); $original_name = rtrim($original_name, "\\/"); unset($matches); if (!preg_match("/^" . nv_preg_quote(NV_ROOTDIR) . "\\/(([a-z0-9\\-\\_\\/]+\\/)*([a-z0-9\\-\\_\\.]+)(\\.(gif|jpg|jpeg|png)))\$/i", $original_name, $matches)) { return false; } $imageinfo = array(); $size = @getimagesize($original_name); if (!$size or !isset($size[0]) or !isset($size[1]) or !$size[0] or !$size[1]) { return false; } $imageinfo['orig_src'] = $imageinfo['src'] = NV_BASE_SITEURL . $matches[1]; $imageinfo['orig_width'] = $imageinfo['width'] = $size[0]; $imageinfo['orig_height'] = $imageinfo['height'] = $size[1]; if ($width) { $imageinfo['width'] = $width; $imageinfo['height'] = ceil($width * $imageinfo['orig_height'] / $imageinfo['orig_width']); } if ($is_create_thumb and $width and $imageinfo['orig_width'] > $width) { if (empty($thumb_path) or !is_dir($thumb_path) or !is_writeable($thumb_path)) { $thumb_path = $matches[2]; } else { $thumb_path = realpath($thumb_path); if (empty($thumb_path)) { $thumb_path = $matches[2]; } else { $thumb_path = str_replace('\\', '/', $thumb_path); unset($matches2); if (preg_match("/^" . nv_preg_quote(NV_ROOTDIR) . "([a-z0-9\\-\\_\\/]+)*\$/i", $thumb_path, $matches2)) { $thumb_path = ltrim($matches2[1], "\\/"); } else { $thumb_path = $matches[2]; } } } if (!empty($thumb_path) and !preg_match("/\\/\$/", $thumb_path)) { $thumb_path = $thumb_path . '/'; } $new_src = $thumb_path . $matches[3] . '_' . $width . $matches[4]; $is_create = true; if (file_exists(NV_ROOTDIR . '/' . $new_src)) { $size = @getimagesize(NV_ROOTDIR . '/' . $new_src); if ($size and isset($size[0]) and isset($size[1]) and $size[0] and $size[1]) { $imageinfo['src'] = NV_BASE_SITEURL . $new_src; $imageinfo['width'] = $size[0]; $imageinfo['height'] = $size[1]; $is_create = false; } } if ($is_create) { include NV_ROOTDIR . "/includes/class/image.class.php"; $image = new image($original_name, NV_MAX_WIDTH, NV_MAX_HEIGHT); $image->resizeXY($width); $image->save(NV_ROOTDIR . '/' . $thumb_path, $matches[3] . '_' . $width . $matches[4]); $image_info = $image->create_Image_info; if (file_exists(NV_ROOTDIR . '/' . $new_src)) { $imageinfo['src'] = NV_BASE_SITEURL . $new_src; $imageinfo['width'] = $image_info['width']; $imageinfo['height'] = $image_info['height']; } } } return $imageinfo; }
} elseif (!empty($rowcontent['homeimgfile'])) { $check_thumb = true; } $homeimgfile = NV_UPLOADS_REAL_DIR . "/" . $module_name . "/" . $rowcontent['homeimgfile']; if ($check_thumb and file_exists($homeimgfile)) { require_once NV_ROOTDIR . "/includes/class/image.class.php"; $basename = basename($homeimgfile); $image = new image($homeimgfile, NV_MAX_WIDTH, NV_MAX_HEIGHT); $thumb_basename = $basename; $i = 1; while (file_exists(NV_UPLOADS_REAL_DIR . '/' . $module_name . '/thumb/' . $thumb_basename)) { $thumb_basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $i . '\\2', $basename); $i++; } $image->resizeXY($module_config[$module_name]['homewidth'], $module_config[$module_name]['homeheight']); $image->save(NV_UPLOADS_REAL_DIR . '/' . $module_name . '/thumb', $thumb_basename); $image_info = $image->create_Image_info; $thumb_name = str_replace(NV_UPLOADS_REAL_DIR . '/' . $module_name . '/', '', $image_info['src']); $block_basename = $basename; $i = 1; while (file_exists(NV_UPLOADS_REAL_DIR . '/' . $module_name . '/block/' . $block_basename)) { $block_basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $i . '\\2', $basename); $i++; } $image->resizeXY($module_config[$module_name]['blockwidth'], $module_config[$module_name]['blockheight']); $image->save(NV_UPLOADS_REAL_DIR . '/' . $module_name . '/block', $block_basename); $image_info = $image->create_Image_info; $block_name = str_replace(NV_UPLOADS_REAL_DIR . '/' . $module_name . '/', '', $image_info['src']); $image->close(); $rowcontent['homeimgthumb'] = $thumb_name . "|" . $block_name; }
/** * save - saves images to path * @param $path string - requires trailing slash '/' * @return string name */ public function save($path) { $this->image->save($path . $this->name); return $this->name; }
public function view_resize_to_height() { if ($this->model->is_loaded) { $height = intval($this->request['height']); if ($height && $height > 0) { $children = $this->model->get(); foreach ($children as $child) { if ($child instanceof \adapt\model && $child->table_name == "image_version") { if ($child->action_resized_to_height == "Yes" && $child->height == $height) { /* Return the child */ $asset_id = md5("image_version-" . $child->image_version_id . "-resize_to_height-h" . $height); $if_none_match = ""; if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) { $if_none_match = str_replace("\"", "", $_SERVER['HTTP_IF_NONE_MATCH']); } if ($if_none_match == $asset_id) { header('HTTP/1.1 304 Not Modified'); header("Cache-Control: public"); header("Expires: "); header("Content-Type: "); header("Etag: \"{$asset_id}\""); exit(1); } else { $cal = new \adapt\date($child->date_modified); $cal->goto_months(11); $this->content_type = $child->content_type; header("Cache-Control: private"); header("Expires: " . $cal->date('D, d M Y H:i:s O')); $cal->goto_months(-11); header("Last-Modified: " . $cal->date('D, d M Y H:i:s O')); header("Etag: \"{$asset_id}\""); $key = $child->file_key; return $this->file_store->get($key); } } } } /* We never found a matching child so we are going to create one */ $image = new image($this->model->file_key); if (count($image->errors() == 0)) { /* Resize */ $image->resize_to_height($height); if ($key = $image->save()) { /* Create a new image version */ $image_version = new model_image_version(); $image_version->action_resized_to_height = 'Yes'; $image_version->height = $height; $image_version->content_type = $this->model->content_type; $image_version->image_id = $this->model->image_id; $image_version->file_key = $key; $image_version->save(); $cal = new \adapt\date($image_version->date_modified); $cal->goto_months(11); $this->content_type = $image_version->content_type; header("Cache-Control: private"); header("Expires: " . $cal->date('D, d M Y H:i:s O')); $cal->goto_months(-11); header("Last-Modified: " . $cal->date('D, d M Y H:i:s O')); header("Etag: \"{$asset_id}\""); return $this->file_store->get($key); } else { $this->error(500); } } else { $this->error(500); } } else { $this->error(500); } } else { $this->error(404); } }
} elseif (!empty($rowcontent['homeimgfile'])) { $check_thumb = true; } $homeimgfile = NV_UPLOADS_REAL_DIR . "/" . $module_name . "/" . $rowcontent['homeimgfile']; if ($check_thumb and file_exists($homeimgfile)) { require_once NV_ROOTDIR . "/includes/class/image.class.php"; $basename = basename($homeimgfile); $image = new image($homeimgfile, NV_MAX_WIDTH, NV_MAX_HEIGHT); $thumb_basename = $basename; $i = 1; while (file_exists(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $module_name . '/thumb/' . $thumb_basename)) { $thumb_basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $i . '\\2', $basename); ++$i; } $image->resizeXY($module_config[$module_name]['homewidth'], $module_config[$module_name]['homeheight']); $image->save(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $module_name . '/thumb', $thumb_basename); $image_info = $image->create_Image_info; $thumb_name = str_replace(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $module_name . '/', '', $image_info['src']); $block_basename = $basename; $i = 1; while (file_exists(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $module_name . '/block/' . $block_basename)) { $block_basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $i . '\\2', $basename); ++$i; } $image->resizeXY($module_config[$module_name]['blockwidth'], $module_config[$module_name]['blockheight']); $image->save(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $module_name . '/block', $block_basename); $image_info = $image->create_Image_info; $block_name = str_replace(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $module_name . '/', '', $image_info['src']); $image->close(); $rowcontent['homeimgthumb'] = $thumb_name . "|" . $block_name; }
/** * Unit test * @param string $file */ public static function run_test() { $img = new image(); $img->load('/tmp/test.jpg'); $img->resize(700); $img->watermark('/tmp/wm.png'); $img->resize(200); $img->save('/tmp/success.png'); }
$w = $logo_size[0]; } else { $w = ceil($photo['width'] * $photo_config['autologosize3'] / 100); } } $h = ceil($w * $logo_size[1] / $logo_size[0]); $x = $photo['width'] - $w - 5; $y = $photo['height'] - $h - 5; $config_logo = array(); $config_logo['x'] = $photo['width'] - $w - 5; $config_logo['y'] = $photo['height'] - $h - 5; $config_logo['w'] = $w; $config_logo['h'] = $h; $createImage = new image($newFilePath, NV_MAX_WIDTH, NV_MAX_HEIGHT); $createImage->addlogo(NV_ROOTDIR . '/' . $upload_logo, '', '', $config_logo); $createImage->save($folder_album, $basename); } $photo['file'] = substr($newFilePath, strlen(NV_UPLOADS_REAL_DIR . '/' . $module_name . '/images/')); // Copy file thumb //$thum_folder = floor( $data['album_id'] / 1000 ); $thumbName = $fileName = substr($photo['thumb'], strlen(NV_BASE_SITEURL . NV_TEMP_DIR . '/')); $fileName2 = $fileName; $i = 1; while (file_exists(NV_ROOTDIR . '/' . $currentpaththumb . '/' . $fileName2)) { $fileName2 = preg_replace('/(.*)(\\.[a-zA-Z0-9]+)$/', '\\1_' . $i . '\\2', $fileName); ++$i; } $fileName = $fileName2; $filePath = NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . $thumbName; $newFilePath = NV_ROOTDIR . '/' . $currentpaththumb . '/' . $fileName; $rename = nv_copyfile($filePath, $newFilePath);
function createthumb($imgpath, $thumbpath, $filename, $thumbwidth, $thumbheight) { global $module_config, $module_name; if (file_exists($imgpath)) { require_once NV_ROOTDIR . "/includes/class/image.class.php"; $basename = basename($imgpath); $image = new image($imgpath, NV_MAX_WIDTH, NV_MAX_HEIGHT); $thumb_basename = $basename; $i = 1; while (file_exists($thumbpath . '/' . $thumb_basename)) { $thumb_basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $i . '\\2', $basename); ++$i; } $image->resizeXY($thumbwidth, $thumbheight); $image->save($thumbpath, $thumb_basename); $image_info = $image->create_Image_info; $thumb_name = str_replace($thumbpath, '', $image_info['src']); $image->close(); return $thumb_name; } else { return false; } }
function nv_news_block_newscenter($block_config) { global $module_data, $module_name, $module_file, $module_upload, $global_array_cat, $global_config, $lang_module, $db, $module_config, $module_info; $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); $list = array_values($list); if (!empty($list)) { $xtpl = new XTemplate('block_newscenter.tpl', NV_ROOTDIR . '/themes/' . $module_info['template'] . '/modules/' . $module_file); $xtpl->assign('lang', $lang_module); $xtpl->assign('TOOLTIP_POSITION', $block_config['tooltip_position']); foreach ($list as $i => $row) { $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['hometext'] = nv_clean60(strip_tags($row['hometext']), 360); $row['titleclean60'] = nv_clean60($row['title'], 60); if ($i == 0) { $width = isset($block_config['width']) ? $block_config['width'] : 400; $height = isset($block_config['height']) ? $block_config['height'] : 268; if ($row['homeimgfile'] != '' and ($imginfo = nv_is_image(NV_UPLOADS_REAL_DIR . '/' . $module_upload . '/' . $row['homeimgfile'])) != array()) { $image = NV_UPLOADS_REAL_DIR . '/' . $module_upload . '/' . $row['homeimgfile']; if ($imginfo['width'] <= $width and $imginfo['height'] <= $height) { $row['imgsource'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module_upload . '/' . $row['homeimgfile']; $row['width'] = $imginfo['width']; } else { $basename = preg_replace('/(.*)(\\.[a-z]+)$/i', $module_name . '_' . $row['id'] . '_\\1_' . $width . '-' . $height . '\\2', basename($image)); if (file_exists(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . $basename)) { $imginfo = nv_is_image(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . $basename); $row['imgsource'] = NV_BASE_SITEURL . NV_TEMP_DIR . '/' . $basename; $row['width'] = $imginfo['width']; } else { $_image = new image($image, NV_MAX_WIDTH, NV_MAX_HEIGHT); $_image->resizeXY($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; $row['width'] = $_image->create_Image_info['width']; } } } } elseif (nv_is_url($row['homeimgfile'])) { $row['imgsource'] = $row['homeimgfile']; $row['width'] = $width; } elseif (!empty($module_config[$module_name]['show_no_image'])) { $row['imgsource'] = NV_BASE_SITEURL . $module_config[$module_name]['show_no_image']; $row['width'] = $width; } else { $row['imgsource'] = NV_BASE_SITEURL . 'themes/' . $global_config['site_theme'] . '/images/no_image.gif'; $row['width'] = $width; } $xtpl->assign('main', $row); } else { if ($row['homeimgthumb'] == 1) { $row['imgsource'] = NV_BASE_SITEURL . NV_FILES_DIR . '/' . $module_upload . '/' . $row['homeimgfile']; } elseif ($row['homeimgthumb'] == 2) { $row['imgsource'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module_upload . '/' . $row['homeimgfile']; } elseif ($row['homeimgthumb'] == 3) { $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.gif'; } $row['hometext'] = nv_clean60($row['hometext'], $block_config['tooltip_length'], true); $xtpl->assign('othernews', $row); if (!$block_config['showtooltip']) { $xtpl->assign('TITLE', 'title="' . $row['title'] . '"'); } if ($block_config['showtooltip']) { $xtpl->parse('main.othernews.tooltip'); } $xtpl->parse('main.othernews'); } } $xtpl->parse('main'); return $xtpl->text('main'); } }
} } elseif (!empty($array['image'])) { $check_thumb = true; } if ($check_thumb and is_file(NV_ROOTDIR . '/' . NV_UPLOADS_DIR . "/" . $module_name . "/topics/" . $array['image'])) { require_once NV_ROOTDIR . "/includes/class/image.class.php"; $basename = basename($array['image']); $image = new image(NV_ROOTDIR . '/' . NV_UPLOADS_DIR . "/" . $module_name . "/topics/" . $array['image'], NV_MAX_WIDTH, NV_MAX_HEIGHT); $thumb_basename = $basename; $i = 1; while (is_file(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $module_name . '/topics/' . $thumb_basename)) { $thumb_basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $i . '\\2', $basename); ++$i; } $image->resizeXY($module_config[$module_name]['homewidth'], $module_config[$module_name]['homeheight']); $image->save(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $module_name . '/topics', $thumb_basename); $image_info = $image->create_Image_info; $array['thumbnail'] = str_replace(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $module_name . '/topics/', '', $image_info['src']); } $array['alias'] = $array['alias'] == "" ? change_alias($array['title']) : change_alias($array['alias']); if (empty($array['title'])) { $error = $lang_module['topics_error_title']; } elseif ($array['topicid'] == 0) { list($weight) = $db->sql_fetchrow($db->sql_query("SELECT max(`weight`) FROM `" . NV_PREFIXLANG . "_" . $module_data . "_topics`")); $weight = intval($weight) + 1; $query = "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "_topics` (`topicid`, `title`, `alias`, `description`, `image`, `thumbnail`, `weight`, `keywords`, `add_time`, `edit_time`) VALUES (NULL, " . $db->dbescape($array['title']) . ", " . $db->dbescape($array['alias']) . ", " . $db->dbescape($array['description']) . ", " . $db->dbescape($array['image']) . ", " . $db->dbescape($array['thumbnail']) . ", " . $db->dbescape($weight) . ", " . $db->dbescape($array['keywords']) . ", UNIX_TIMESTAMP( ), UNIX_TIMESTAMP( ))"; if ($db->sql_query_insert_id($query)) { nv_insert_logs(NV_LANG_DATA, $module_name, 'log_add_topic', " ", $admin_info['userid']); $db->sql_freeresult(); Header("Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $op . ""); die;
function nv_news_block_news($block_config, $mod_data) { global $module_array_cat, $module_info, $db, $module_config, $global_config; $module = 'news'; $blockwidth = $module_config[$module]['blockwidth']; $show_no_image = $module_config[$module]['show_no_image']; $numrow = isset($block_config['numrow']) ? $block_config['numrow'] : 20; $cache_file = NV_LANG_DATA . '__block_news_' . $numrow . '_' . NV_CACHE_PREFIX . '.cache'; if (($cache = nv_get_cache($module, $cache_file)) != false) { $array_block_news = unserialize($cache); } else { $array_block_news = array(); $db->sqlreset()->select('id, catid, publtime, exptime, title, alias, homeimgthumb, homeimgfile, hometext')->from(NV_PREFIXLANG . '_' . $mod_data . '_rows')->where('status= 1')->order('publtime DESC')->limit($numrow); $result = $db->query($db->sql()); while (list($id, $catid, $publtime, $exptime, $title, $alias, $homeimgthumb, $homeimgfile, $hometext) = $result->fetch(3)) { $link = NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module . '&' . NV_OP_VARIABLE . '=' . $module_array_cat[$catid]['alias'] . '/' . $alias . '-' . $id . $global_config['rewrite_exturl']; $array_block_news[] = array('id' => $id, 'title' => $title, 'link' => $link, 'homeimgfile' => $homeimgfile, 'width' => $blockwidth, 'hometext' => $hometext); } $cache = serialize($array_block_news); nv_set_cache($module, $cache_file, $cache); } if (file_exists(NV_ROOTDIR . '/themes/' . $module_info['template'] . '/blocks/block_news.tpl')) { $block_theme = $module_info['template']; } else { $block_theme = 'default'; } $xtpl = new XTemplate('block_news.tpl', NV_ROOTDIR . '/themes/' . $block_theme . '/blocks/'); $i = 1; foreach ($array_block_news as $array_news) { $array_news['hometext'] = nv_clean60($array_news['hometext'], 20); $image = NV_UPLOADS_REAL_DIR . '/' . $module . '/' . $array_news['homeimgfile']; if ($array_news['homeimgfile'] != '' and file_exists($image)) { if ($i == 1) { $width = 370; $height = 150; } else { $width = 170; $height = 115; } $array_news['imgurl'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module_name . '/' . $array_news['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)) { $array_news['imgurl'] = 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)) { $array_news['imgurl'] = NV_BASE_SITEURL . NV_TEMP_DIR . '/' . $basename; } } } } elseif (nv_is_url($array_news['homeimgfile'])) { $array_news['imgurl'] = $array_news['homeimgfile']; } elseif (!empty($module_config[$module_name]['show_no_image'])) { $array_news['imgurl'] = NV_BASE_SITEURL . $module_config[$module_name]['show_no_image']; } else { $array_news['imgurl'] = NV_BASE_SITEURL . 'themes/' . $global_config['site_theme'] . '/images/no-image.png'; } $xtpl->assign('blocknews', $array_news); if ($i == 1) { $xtpl->parse('main.news_main'); } else { $array_news['title0'] = nv_clean60($array_news['title'], 40); $xtpl->assign('blocknews', $array_news); $xtpl->assign('FL', $i % 2 != 0 ? 'right' : 'left'); $xtpl->parse('main.newsloop'); } $i++; } $xtpl->parse('main'); return $xtpl->text('main'); }
function createNewObject($object_type, $post_vars, $system_data_classes, $object_save = 0) { if (!$object_type) { return false; } if (!in_array($object_type, $system_data_classes)) { return false; } switch ($object_type) { case "page": $object = new page("new page"); $object->update_document_props($post_vars); if ($object_save == 1) { $object->createContent(); $object->save(); } break; case "process": $object = new process("new process"); $object->update_document_props($post_vars); $object->update_design_props($post_vars); if ($object_save == 1) { $object->save(); } break; case "section": $object = new section("new section"); $object->update_document_props($post_vars); if ($object_save == 1) { $object->createContent(); $object->save(); } break; case "image": $object = new image("new image"); $object->update_document_props($post_vars); if ($object_save == 1) { $object->save(); } break; case "file": $object = new file("new file"); $object->update_document_props($post_vars); if ($object_save == 1) { $object->save(); } break; default: break; } return $object; }
$data['v_path'] = filter_text_input('v_path', 'post', '', 0); $data['description'] = filter_text_textarea('description', '', NV_ALLOWED_HTML_TAGS); $data['is_show'] = filter_text_input('is_show', 'post', '0', 0); if (!empty($data['v_path']) and file_exists(NV_DOCUMENT_ROOT . $data['v_path'])) { $lu = strlen(NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name); $data['v_path'] = substr($data['v_path'], $lu); } elseif (!nv_is_url($data['v_path']) and !empty($data['v_path'])) { $data['v_path'] = ""; } if (!empty($data['path']) and file_exists(NV_DOCUMENT_ROOT . $data['path'])) { $homeimgfile = NV_DOCUMENT_ROOT . $data['path']; require_once NV_ROOTDIR . "/includes/class/image.class.php"; $basename = basename($homeimgfile); $image = new image($homeimgfile, NV_MAX_WIDTH, NV_MAX_HEIGHT); $image->resizeXY($max_x, $max_y); $image->save(NV_UPLOADS_REAL_DIR . '/' . $module_name . '/thumb', $basename); $image_info = $image->create_Image_info; $image->close(); $thumb_name = str_replace(NV_UPLOADS_REAL_DIR . '/' . $module_name . '/', '', $image_info['src']); $lu = strlen(NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name); $data['path'] = substr($data['path'], $lu); } elseif (!nv_is_url($data['path']) and !empty($data['path'])) { $data['path'] = ""; } if ($data['albumid'] > 0) { if (empty($data['name'])) { $error = $lang_module['err_null_name']; } else { if (empty($data['v_path'])) { $error = $lang_module['err_null_path']; } elseif (empty($error)) {
function resizeimg($folder, $linkanh) { global $global_config, $module, $module_name, $module_config; require_once NV_ROOTDIR . "/includes/class/image.class.php"; $basename = basename($linkanh); $i = 1; while (file_exists(NV_UPLOADS_REAL_DIR . '/' . $module_config[$module_name]['module'] . '/' . $folder . '/' . $basename)) { $basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $i . '\\2', $basename); $i++; } $image = new image($linkanh); $image_info1 = $image->fileinfo; if ($image_info1['width'] > $module_config[$module_name]['bodyimg']) { $image->resizeXY($module_config[$module_name]['bodyimg'], NV_MAX_HEIGHT); } $thumb_basename = $basename; $image->save(NV_UPLOADS_REAL_DIR . '/' . $module_config[$module_name]['module'] . '/' . $folder, $thumb_basename); $image_info = $image->create_Image_info; $img = str_replace(NV_UPLOADS_REAL_DIR . '/' . $module_config[$module_name]['module'] . '/', '', $image_info['src']); $image->close(); return $img; }
/** * nv_get_viewImage() * * @param mixed $fileName * @param integer $w * @param integer $h * @return */ function nv_get_viewImage($fileName, $w = 80, $h = 80) { $ext = nv_getextension($fileName); $md5_view_image = md5($fileName); $viewDir = NV_FILES_DIR . '/images'; $viewFile = $viewDir . '/' . $md5_view_image . '.' . $ext; if (file_exists(NV_ROOTDIR . '/' . $viewFile)) { $size = @getimagesize(NV_ROOTDIR . '/' . $viewFile); return array($viewFile, $size[0], $size[1]); } include_once NV_ROOTDIR . "/includes/class/image.class.php"; $image = new image(NV_ROOTDIR . '/' . $fileName, NV_MAX_WIDTH, NV_MAX_HEIGHT); $image->resizeXY($w, $h); $image->save(NV_ROOTDIR . '/' . $viewDir, $md5_view_image, 75); $create_Image_info = $image->create_Image_info; $error = $image->error; $image->close(); if (empty($error)) { return array($viewDir . '/' . basename($create_Image_info['src']), $create_Image_info['width'], $create_Image_info['height']); } return false; }
} else { $upload = new upload(array('images'), $global_config['forbid_extensions'], $global_config['forbid_mimes'], NV_UPLOAD_MAX_FILESIZE, NV_MAX_WIDTH, NV_MAX_HEIGHT); // Storage in temp dir $upload_info = $upload->save_file($_FILES['image_file'], NV_ROOTDIR . '/' . NV_TEMP_DIR, false); // Delete upload tmp @unlink($_FILES['image_file']['tmp_name']); if (empty($upload_info['error'])) { $basename = $upload_info['basename']; $basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . nv_genpass(8) . "_" . $user_info['userid'] . '\\2', $basename); $image = new image($upload_info['name'], NV_MAX_WIDTH, NV_MAX_HEIGHT); // Resize image, crop image $image->resizeXY($array['w'], $array['h']); $image->cropFromLeft($array['x1'], $array['y1'], $array['avatar_width'], $array['avatar_height']); $image->resizeXY($global_config['avatar_width'], $global_config['avatar_height']); // Save new image $image->save(NV_ROOTDIR . '/' . NV_TEMP_DIR, $basename); $image->close(); if (file_exists($image->create_Image_info['src'])) { $array['success'] = true; $array['filename'] = str_replace(NV_ROOTDIR . '/' . NV_TEMP_DIR . '/', '', $image->create_Image_info['src']); } else { $array['error'] = $lang_module['avata_error_save']; } @nv_deletefile($upload_info['name']); } else { $array['error'] = $upload_info['error']; } } } $contents = nv_avatar($array); include NV_ROOTDIR . '/includes/header.php';
$file_size = $upload_info['img_info']; if ($file_size[0] <= 150) { $w = ceil($logo_size[0] * $global_config['autologosize1'] / 100); } elseif ($file_size[0] < 350) { $w = ceil($logo_size[0] * $global_config['autologosize2'] / 100); } else { if (ceil($file_size[0] * $global_config['autologosize3'] / 100) > $logo_size[0]) { $w = $logo_size[0]; } else { $w = ceil($file_size[0] * $global_config['autologosize3'] / 100); } } $h = ceil($w * $logo_size[1] / $logo_size[0]); $x = $file_size[0] - $w - 5; $y = $file_size[1] - $h - 5; $config_logo = array(); $config_logo['x'] = $file_size[0] - $w - 5; $config_logo['y'] = $file_size[1] - $h - 5; $config_logo['w'] = $w; $config_logo['h'] = $h; require_once NV_ROOTDIR . "/includes/class/image.class.php"; $createImage = new image(NV_ROOTDIR . '/' . $path . '/' . $upload_info['basename'], NV_MAX_WIDTH, NV_MAX_HEIGHT); $createImage->addlogo(NV_ROOTDIR . '/' . $upload_logo, '', '', $config_logo); $createImage->save(NV_ROOTDIR . '/' . $path, $upload_info['basename']); } } } nv_filesList($path, false, $upload_info['basename']); nv_insert_logs(NV_LANG_DATA, $module_name, $lang_module['upload_file'], $path . "/" . $upload_info['basename'], $admin_info['userid']); echo $upload_info['basename']; exit;
$_image = new image($imageSrc); if ($_image->fileinfo['width'] > 50) { if ($_image->fileinfo['width'] > NV_MAX_WIDTH) { $_image->resizeXY(NV_MAX_WIDTH, NV_MAX_HEIGHT); } $basename = explode(".", basename($imageSrc)); array_pop($basename); $basename = implode("-", $basename); $basename = preg_replace('/^\\W+|\\W+$/', '', $basename); $basename = preg_replace('/[ ]+/', '_', $basename); $basename = strtolower(preg_replace('/\\W-/', '', $basename)); $basename .= '.' . $_image->fileinfo['ext']; $thumb_basename = $basename; $i = 1; while (file_exists(NV_ROOTDIR . '/' . $currentpath . '/' . $thumb_basename)) { $thumb_basename = preg_replace('/(.*)(\\.[a-zA-Z]+)$/', '\\1_' . $i . '\\2', $basename); $i++; } $_image->save(NV_ROOTDIR . '/' . $currentpath, $thumb_basename); $image_path = $_image->create_Image_info['src']; if (!empty($image_path) and file_exists($image_path)) { $new_imageSrc = str_replace(NV_ROOTDIR . '/' . $currentpath . '/', NV_BASE_SITEURL . $currentpath . '/', $image_path); $data = str_replace("src=\"" . $imageSrc . "\"", "src=\"" . $new_imageSrc . "\"", $data); } } } } } include NV_ROOTDIR . '/includes/header.php'; echo $data; include NV_ROOTDIR . '/includes/footer.php';
function nv_get_viewImage($fileName) { global $array_thumb_config; if (preg_match('/^' . nv_preg_quote(NV_UPLOADS_DIR) . '\\/(([a-z0-9\\-\\_\\/]+\\/)*([a-z0-9\\-\\_\\.]+)(\\.(gif|jpg|jpeg|png)))$/i', $fileName, $m)) { $viewFile = NV_FILES_DIR . '/' . $m[1]; if (file_exists(NV_ROOTDIR . '/' . $viewFile)) { $size = @getimagesize(NV_ROOTDIR . '/' . $viewFile); return array($viewFile, $size[0], $size[1]); } else { $m[2] = rtrim($m[2], '/'); if (isset($array_thumb_config[NV_UPLOADS_DIR . '/' . $m[2]])) { $thumb_config = $array_thumb_config[NV_UPLOADS_DIR . '/' . $m[2]]; } else { $thumb_config = $array_thumb_config['']; $_arr_path = explode('/', NV_UPLOADS_DIR . '/' . $m[2]); while (sizeof($_arr_path) > 1) { array_pop($_arr_path); $_path = implode('/', $_arr_path); if (isset($array_thumb_config[$_path])) { $thumb_config = $array_thumb_config[$_path]; break; } } } $viewDir = NV_FILES_DIR; if (!empty($m[2])) { if (!is_dir(NV_ROOTDIR . '/' . $m[2])) { $e = explode('/', $m[2]); $cp = NV_FILES_DIR; foreach ($e as $p) { if (is_dir(NV_ROOTDIR . '/' . $cp . '/' . $p)) { $viewDir .= '/' . $p; } else { $mk = nv_mkdir(NV_ROOTDIR . '/' . $cp, $p); if ($mk[0] > 0) { $viewDir .= '/' . $p; } } $cp .= '/' . $p; } } } $image = new image(NV_ROOTDIR . '/' . $fileName, NV_MAX_WIDTH, NV_MAX_HEIGHT); if ($thumb_config['thumb_type'] == 4) { $thumb_width = $thumb_config['thumb_width']; $thumb_height = $thumb_config['thumb_height']; $maxwh = max($thumb_width, $thumb_height); if ($image->fileinfo['width'] > $image->fileinfo['height']) { $thumb_config['thumb_width'] = 0; $thumb_config['thumb_height'] = $maxwh; } else { $thumb_config['thumb_width'] = $maxwh; $thumb_config['thumb_height'] = 0; } } $image->resizeXY($thumb_config['thumb_width'], $thumb_config['thumb_height']); if ($thumb_config['thumb_type'] == 4) { $image->cropFromCenter($thumb_width, $thumb_height); } $image->save(NV_ROOTDIR . '/' . $viewDir, $m[3] . $m[4], $thumb_config['thumb_quality']); $create_Image_info = $image->create_Image_info; $error = $image->error; $image->close(); if (empty($error)) { return array($viewDir . '/' . basename($create_Image_info['src']), $create_Image_info['width'], $create_Image_info['height']); } } } else { $size = @getimagesize(NV_ROOTDIR . '/' . $fileName); return array($viewFile, $size[0], $size[1]); } return false; }