public function getThumb($width, $height, $mode) { Log::debug("{$width},{$height}"); $dirThumb = "{$this->dir}/.thumbs/{$width}_{$height}_{$mode}"; $pathThumb = $dirThumb . '/' . $this->name . '.jpg'; if (!file_exists(Lib::gpath() . $pathThumb)) { $dir = Lib::gpath($dirThumb); if (!is_dir($dir)) { if (!is_dir($this->getDir() . '/.thumbs')) { mkdir($this->getDir() . '/.thumbs'); } mkdir($dir); } $t = new Image_Toolbox($this->getPath()); $t->newOutputSize($width, $height, $mode, false, '#FFFFFF'); $t->save(Lib::gpath() . $pathThumb, 'jpg', 80); } return $pathThumb; }
if (!file_exists("{$imagePath}/{$imageName}")) { $imagePath = $baseDir . '/' . UPLOAD_DIR . '/images'; } if (!file_exists("{$imagePath}/{$imageName}")) { exit(0); } $save = false; } if ($width > MAX_SIZE) { $width = MAX_SIZE; } if ($height > MAX_SIZE) { $height = MAX_SIZE; } require $baseDir . '/class/class.thumbnail.php'; $thumb = new Image_Toolbox("{$imagePath}/{$imageName}"); switch ($method) { case 'r': $thumb->newOutputSize((int) $width, (int) $height, 0, (bool) $rotate); break; case 'c': $thumb->newOutputSize((int) $width, (int) $height, 1, (bool) $rotate); break; case 'f': $thumb->newOutputSize((int) $width, (int) $height, 2, false, '#ffffff'); break; case 't': $thumb->newOutputSize((int) $width, (int) $height, 3, false); break; } $thumb->output();
function GetThumb($dir, $md5, $filename, $mode, $width=100, $height=100) { $path = realpath(DIR_ROOT.'/'.$dir); if(is_file($path.'/.thumbs/'.$md5.'_'.$width.'_'.$height.'_'.$mode.'.jpg')) return $dir.'/.thumbs/'.$md5.'_'.$width.'_'.$height.'_'.$mode.'.jpg'; $isfile = (strpos($dir, DIR_FILES) === 0 ? true : false); if ($isfile) { $server_url = rtrim(dirname(__FILE__), '/').'/../../'; $server_url = realpath($server_url); $server_url = rtrim($server_url, '/').'/img/fileicons/'; $url = '/'.ltrim(substr($server_url, strlen(DIR_ROOT)), '/'); $ext = strtolower(end(explode('.', $filename))); if (!empty($ext) && file_exists($server_url.$ext.'.png')) { return $url.$ext.'.png'; } else { return $url.'none.png'; } } $t = new Image_Toolbox($path.'/'.$filename); $t->newOutputSize($width, $height, $mode, false, '#FFFFFF'); $t->save($path.'/.thumbs/'.$md5.'_'.$width.'_'.$height.'_'.$mode.'.jpg', 'jpg', 80); return $dir.'/.thumbs/'.$md5.'_'.$width.'_'.$height.'_'.$mode.'.jpg'; }
/** * @see Rabbit_Field_File::postChange() * * @param unknown_type $id */ public function postChange($id) { if ($this->hasUpload()) { $ci =& get_instance(); $ci->load->helper('rabbit'); $this->getForm()->removeHiddenField($this->getName()); $modes = array('fix' => 0, 'crop' => 1, 'preserve' => 2); $file = $_FILES[$this->getName()]; //add new file $path = $this->baseFilePath(); //make dir if not exists if (!is_dir($path)) { mkdir($path); } $path .= $id . '_' . $file['name']; $filename = rabbit_pathinfo($file['name'], RABBITPATH_FILENAME); $filetype = $this->getAttribute('output_type', pathinfo($file['name'], PATHINFO_EXTENSION)); $img = new Image_Toolbox($file['tmp_name']); if ($this->getAttribute('resize_width') || $this->getAttribute('resize_height')) { $img->newOutputSize($this->getAttribute('resize_width', 0), $this->getAttribute('resize_height', 0), $modes[$this->getAttribute('resize_mode', 'fix')], false, $this->getAttribute('resize_bgcolor', '#000000')); } $img->save($this->baseFilePath() . $id . '_' . $filename . '.' . $filetype, $filetype); $copies = $this->getAttribute('copies', array()); foreach ($copies as $copy) { $filetype = isset($copy['output_type']) ? $copy['output_type'] : pathinfo($file['name'], PATHINFO_EXTENSION); $label = isset($copy['label']) ? $copy['label'] : ''; $img = new Image_Toolbox($file['tmp_name']); $img->newOutputSize(isset($copy['resize_width']) ? $copy['resize_width'] : 0, isset($copy['resize_height']) ? $copy['resize_height'] : 0, $modes[isset($copy['resize_mode']) ? $copy['resize_mode'] : 'fix'], false, isset($copy['resize_bgcolor']) ? $copy['resize_bgcolor'] : '#000000'); $img->save($this->baseFilePath() . $id . '_' . $label . '_' . $filename . '.' . $filetype, $filetype); } } }
function GetThumb($dir, $md5, $filename, $mode, $width = 100, $height = 100) { $path = realpath(DIR_ROOT . '/' . $dir); if (is_file($path . '/_thumbs/' . $md5 . '_' . $width . '_' . $height . '_' . $mode . '.jpg')) { return $dir . '/_thumbs/' . $md5 . '_' . $width . '_' . $height . '_' . $mode . '.jpg'; } $t = new Image_Toolbox($path . '/' . $filename); $t->newOutputSize($width, $height, $mode, false, '#FFFFFF'); $t->save($path . '/_thumbs/' . $md5 . '_' . $width . '_' . $height . '_' . $mode . '.jpg', 'jpg', 80); return $dir . '/_thumbs/' . $md5 . '_' . $width . '_' . $height . '_' . $mode . '.jpg'; }
@date_default_timezone_set('Europe/Moscow'); ob_start(); define('BASE_DIR', str_replace("\\", "/", dirname(dirname(__FILE__)))); define('MEDIAPATH', 'uploads'); $max_size = 128; // максимальный размер миниатюры define('TH_PREF', 'thumbnail/th_' . $max_size . '_'); // префикс миниатюр define('UPDIR', BASE_DIR . '/' . MEDIAPATH); if (isset($_REQUEST['thumb']) && $_REQUEST['thumb'] == 1) { $img_path = str_replace(array('../', './', '..', '\'', '//'), '', $_REQUEST['bild']); $img_path = '/' . ltrim($img_path, '/'); $img_dir = rtrim(dirname($img_path), '/') . '/'; $img_name = basename($img_path); require BASE_DIR . '/class/class.thumbnail.php'; $img = new Image_Toolbox(UPDIR . $img_path); $img->newOutputSize($max_size, $max_size, 2, false, '#EFF3EB'); // $img->newOutputSize($max_size, $max_size, 2, false, '#FFFFFF'); $img->output(); // Проверяем наличие папки для миниатюр и если её нет - создаём if (!file_exists(UPDIR . $img_dir . '/thumbnail')) { $oldumask = umask(0); @mkdir(UPDIR . $img_dir . '/thumbnail', 0777); umask($oldumask); } $img->save(UPDIR . $img_dir . TH_PREF . $img_name); $oldumask = umask(0); chmod(UPDIR . $img_dir . TH_PREF . $img_name, 0644); umask($oldumask); exit; }
header('Content-Type:' . $img_data['mime'], true); header("Last-Modified: " . gmdate("D, d M Y H:i:s" . filemtime($thumb_file)) . " GMT"); header("Content-Length: " . (string) filesize($thumb_file), true); readfile($thumb_file); exit; } // Проверяем наличие папки для миниатюр и если её нет - создаём if (!file_exists($file_dir . '/thumbnail')) { $oldumask = umask(0); @mkdir($file_dir . '/thumbnail', 0777); umask($oldumask); } } elseif (!($file = realpath(BASE_DIR . '/uploads/images/noimage.gif'))) { exit; } define('IMAGE_TOOLBOX_DEFAULT_JPEG_QUALITY', 75); require BASE_DIR . '/class/class.thumbnail.php'; $img = new Image_Toolbox($file); // если указано, что не обрезать, а помещать в установленные размеры, и при этом эти размеры явно заданы... $img->newOutputSize($width, $height, 1, false); //$img->addText('AVE.cms 2.09', BASE_DIR . '/inc/fonts/ft16.ttf', 16, '#709536', 'right -10', 'bottom -10'); header('Content-Type:' . $img_data['mime'], true); header("Last-Modified: " . gmdate("D, d M Y H:i:s" . filemtime($thumb_file)) . " GMT"); header("Content-Length: " . (string) filesize($thumb_file), true); if (!empty($thumb_file)) { $img->save($thumb_file); $oldumask = umask(0); chmod($thumb_file, 0644); umask($oldumask); } $img->output();
private function useToolboxToLimit($width, $height) { $name = tempnam('/tmp', 'lame-toolbox'); file_put_contents($name, $this->binary); $image = new Image_Toolbox($name); $image->newOutputSize((int) $width, (int) $height, 1); $binary = $image->asString(); /* header('Content-Type: image/jpeg'); print $binary; exit(0); */ unlink($name); return $binary; }
$source_dir = dirname(__FILE__) . rtrim('/uploads/' . $source_dir, '/'); if ($file = realpath($source_dir . '/' . $source_file)) { $thumb_file = $source_dir . '/th__' . $source_file; // Если не указано обязательное формирование миниатюр (&compile=1) // и есть миниатюра сформированная ранее - выводим её if (file_exists($thumb_file) && empty($_REQUEST['compile'])) { $img_data = @getimagesize($file); header('Content-Type:' . $img_data['mime'], true); readfile($thumb_file); exit; } } else { exit; } break; case 'video': if (!($file = realpath(dirname(__FILE__) . '/uploads/dummy_video.gif'))) { exit; } break; } if (!@(include mb_substr(dirname(__FILE__), 0, -16) . '/class/class.thumbnail.php')) { die; } $img = new Image_Toolbox($file); $img->newOutputSize($width, $width, 1); $img->output(); if (!empty($thumb_file)) { $img->save($thumb_file); chmod($thumb_file, 0644); }