private function generateThumbnail($destination, $filename, $size) { $thumbDestination = $destination . $size . DS; if (!is_dir($thumbDestination)) { mkdir($thumbDestination, 0777, true); } $imageSettings = $this->getConfig(); if (sizeof($imageSettings) == 0) { return false; } $thumb = new phpThumb(); foreach ($imageSettings[$size] as $key => $value) { $thumb->setParameter($key, $value); } $thumb->setSourceData(file_get_contents($destination . $filename)); if ($thumb->GenerateThumbnail()) { // this line is VERY important, do not remove it! if ($thumb->RenderToFile($thumbDestination . $filename)) { return true; } else { throw new Exception("Nie udało mi się wygenerować miniaturki o rozmiarze - {$size} Ponieważ:\n {$thumb->debugmessages}"); } } else { throw new Exception("Błąd generatora\n {$thumb->debugmessages}"); } return false; }
public function action_zip($articulo_id) { include DOCROOT . 'phpthumb/phpthumb.class.php'; \Config::load('phpthumb'); $document_root = str_replace("\\", "/", Config::get('document_root')); is_null($articulo_id) and Response::redirect('articulo'); $articulo = Model_Articulo::find('first', array('related' => array('fotos', 'seccion'), 'where' => array(array('id', '=', $articulo_id)))); $fotos_web = null; foreach ($articulo->fotos as $foto) { $phpThumb = new phpThumb(); $phpThumb->setParameter('w', Config::get('web_size')); $phpThumb->setParameter('q', 75); $phpThumb->setParameter('aoe', true); $phpThumb->setParameter('config_output_format', 'jpeg'); $phpThumb->setParameter('f', 'jpeg'); $nombre_archivo = str_ireplace(".jpg", Config::get('photos_texto') . '.jpg', $foto->imagen); $pieces = explode("/", $nombre_archivo); $count_foto = count($pieces); $nombre_archivo = $pieces[$count_foto - 1]; $output_filename = $document_root . "/web/" . $nombre_archivo; $phpThumb->setSourceData(file_get_contents($document_root . $foto->imagen)); if ($phpThumb->GenerateThumbnail()) { if ($phpThumb->RenderToFile($output_filename)) { Log::info('Imagen para web generada con exito' . $output_filename); $fotos_web[] = $output_filename; } else { Log::info('Error al generar imagen para web ' . $phpThumb->debugmessages); } $phpThumb->purgeTempFiles(); } else { Log::info('Error Fatal al generar imagen para web ' . $phpThumb->fatalerror . "|" . $phpThumb->debugmessages); } unset($phpThumb); } $time = time(); Zip::create_zip($fotos_web, $articulo_id, true, $time); }
$parsed_url_referer = phpthumb_functions::ParseURLbetter(@$_SERVER['HTTP_REFERER']); if ($phpThumb->config_nooffsitelink_require_refer && !in_array(@$parsed_url_referer['host'], $phpThumb->config_nohotlink_valid_domains)) { $phpThumb->ErrorImage('config_nooffsitelink_require_refer enabled and ' . (@$parsed_url_referer['host'] ? '"' . $parsed_url_referer['host'] . '" is not an allowed referer' : 'no HTTP_REFERER exists')); } $parsed_url_src = phpthumb_functions::ParseURLbetter(@$_GET['src']); if ($phpThumb->config_nohotlink_enabled && $phpThumb->config_nohotlink_erase_image && preg_match('/^(f|ht)tps?\\:\\/\\//i', @$_GET['src']) && !in_array(@$parsed_url_src['host'], $phpThumb->config_nohotlink_valid_domains)) { $phpThumb->ErrorImage($phpThumb->config_nohotlink_text_message); } if ($phpThumb->config_mysql_query) { if ($cid = @mysql_connect($phpThumb->config_mysql_hostname, $phpThumb->config_mysql_username, $phpThumb->config_mysql_password)) { if (@mysql_select_db($phpThumb->config_mysql_database, $cid)) { if ($result = @mysql_query($phpThumb->config_mysql_query, $cid)) { if ($row = @mysql_fetch_array($result)) { mysql_free_result($result); mysql_close($cid); $phpThumb->setSourceData($row[0]); unset($row); } else { mysql_free_result($result); mysql_close($cid); $phpThumb->ErrorImage('no matching data in database.'); } } else { mysql_close($cid); $phpThumb->ErrorImage('Error in MySQL query: "' . mysql_error($cid) . '"'); } } else { mysql_close($cid); $phpThumb->ErrorImage('cannot select MySQL database: "' . mysql_error($cid) . '"'); } } else {
$parsed_url_referer = phpthumb_functions::ParseURLbetter(@$_SERVER['HTTP_REFERER']); if ($phpThumb->config_nooffsitelink_require_refer && !in_array(@$parsed_url_referer['host'], $phpThumb->config_nohotlink_valid_domains)) { $phpThumb->ErrorImage('config_nooffsitelink_require_refer enabled and ' . (@$parsed_url_referer['host'] ? '"' . $parsed_url_referer['host'] . '" is not an allowed referer' : 'no HTTP_REFERER exists')); } $parsed_url_src = phpthumb_functions::ParseURLbetter(@$_GET['src']); if ($phpThumb->config_nohotlink_enabled && $phpThumb->config_nohotlink_erase_image && preg_match('#^(f|ht)tps?://#i', @$_GET['src']) && !in_array(@$parsed_url_src['host'], $phpThumb->config_nohotlink_valid_domains)) { $phpThumb->ErrorImage($phpThumb->config_nohotlink_text_message); } if ($phpThumb->config_mysql_query) { if ($cid = @mysql_connect($phpThumb->config_mysql_hostname, $phpThumb->config_mysql_username, $phpThumb->config_mysql_password)) { if (@mysql_select_db($phpThumb->config_mysql_database, $cid)) { if ($result = @mysql_query($phpThumb->config_mysql_query, $cid)) { if ($row = @mysql_fetch_array($result)) { mysql_free_result($result); mysql_close($cid); $phpThumb->setSourceData($row[0]); unset($row); } else { mysql_free_result($result); mysql_close($cid); $phpThumb->ErrorImage('no matching data in database.'); } } else { mysql_close($cid); $phpThumb->ErrorImage('Error in MySQL query: "' . mysql_error($cid) . '"'); } } else { mysql_close($cid); $phpThumb->ErrorImage('cannot select MySQL database: "' . mysql_error($cid) . '"'); } } else {
////////////////////////////////////////////////////////////// // Note: phpThumb.php is where the caching code is located, if // you instantiate your own phpThumb() object that code is // bypassed and it's up to you to handle the reading and // writing of cached files, if appropriate. die('For security reasons, this demo is disabled by default. Please comment out line ' . __LINE__ . ' in ' . basename(__FILE__)); require_once '../phpthumb.class.php'; // create phpThumb object $phpThumb = new phpThumb(); $thumbnail_width = 100; // set data source -- do this first, any settings must be made AFTER this call if (is_uploaded_file(@$_FILES['userfile']['tmp_name'])) { $phpThumb->setSourceFilename($_FILES['userfile']['tmp_name']); $output_filename = './thumbnails/' . basename($_FILES['userfile']['name']) . '_' . $thumbnail_width . '.' . $phpThumb->config_output_format; } else { $phpThumb->setSourceData(file_get_contents('..\\images\\disk.jpg')); $output_filename = './thumbnails/disk_small.jpg'; } // PLEASE NOTE: // You must set any relevant config settings here. The phpThumb // object mode does NOT pull any settings from phpThumb.config.php //$phpThumb->setParameter('config_document_root', '/home/groups/p/ph/phpthumb/htdocs/'); //$phpThumb->setParameter('config_cache_directory', '/tmp/persistent/phpthumb/cache/'); // set parameters (see "URL Parameters" in phpthumb.readme.txt) $phpThumb->setParameter('w', $thumbnail_width); //$phpThumb->setParameter('fltr', 'gam|1.2'); //$phpThumb->setParameter('fltr', 'wmi|../watermark.jpg|C|75|20|20'); // generate & output thumbnail if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it! if ($phpThumb->RenderToFile($output_filename)) {