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; }
if (!file_exists('../config/config.yml')) { echo "NO EXISTE EL FICHERO DE CONFIGURACION"; exit; } if (file_exists("../bin/yaml/lib/sfYaml.php")) { include "../bin/yaml/lib/sfYaml.php"; } else { echo "NO EXISTE LA CLASE PARA LEER ARCHIVOS YAML"; exit; } // --------------------------------------------------------------- // CARGO LOS PARAMETROS DE CONFIGURACION. // --------------------------------------------------------------- $config = sfYaml::load('../config/config.yml'); $app = $config['config']['app']; // --------------------------------------------------------------- // ACTIVAR EL AUTOLOADER DE CLASES Y FICHEROS A INCLUIR // --------------------------------------------------------------- define("APP_PATH", $_SERVER['DOCUMENT_ROOT'] . $app['path'] . "/"); include_once "../" . $app['framework'] . "Autoloader.class.php"; Autoloader::setCacheFilePath(APP_PATH . 'tmp/class_path_cache.txt'); Autoloader::excludeFolderNamesMatchingRegex('/^CVS|\\..*$/'); Autoloader::setClassPaths(array('../' . $app['framework'], '../entities/', '../lib/')); spl_autoload_register(array('Autoloader', 'loadClass')); $fileName = "../docs/docs" . $_SESSION['emp'] . "/catalog/" . $_GET['img']; if (file_exists($fileName)) { $thumb = new Thumb(); $thumb->loadImage($fileName); $thumb->resize($_GET['w'], 'width'); $thumb->show(); }
private function show_image($pid, $type, $is_animate = FALSE) { $this->set_browsercache(); if ($type > 0) { //如果是缩略图 /* $client= new GearmanClient(); $client->addServers(Core::config('job_servers')); $client->setTimeout(3000); $result = @ $client->doHigh("thumbnail", serialize(array($pid, $type))); $result && $sid = @ unserialize($result); */ if ($sid) { $source = new Models\PhotoSource(); $source->findOne($sid); $source->output(); //异步缩略图 } else { $thumb = new Thumb(); if ($thumb->resize(NULL, $pid, $type, $is_animate)) { $thumb->output(); //同步缩略图 } } } else { $photoModel = new Models\Photo(); $photoModel->findOne($pid); $photosource = $photoModel->getSource(); if ($photosource) { $photosource->output(); } } }
private function _processUpload($uploader, $cid = 0) { $photoModel = new Models\Photo(); if ($photoModel->create($uploader, array('cid' => $cid))) { $result['id'] = $photoModel->get_pid(); $result['md5'] = $photoModel->md5; $result['width'] = $photoModel->width; $result['height'] = $photoModel->height; $result['mime'] = $photoModel->mime; $result['is_animated'] = $photoModel->is_animated; $imgurls = $photoModel->geturi($result['id'], 130); $result['src'] = $imgurls[0]; $thumb = new Thumb(); $thumb->resize(NULL, $result['id'], 130); $client = new GearmanClient(); $client->addServers(Core::config('job_servers')); $client->addTaskLowBackground("thumbnail", serialize(array($result['id'], 320))); $client->addTaskLowBackground("thumbnail", serialize(array($result['id'], 780))); $client->addTaskLowBackground("thumbnail", serialize(array($result['id'], 1600))); @$client->runTasks(); return $result; } else { return FALSE; } }