本文整理匯總了PHP中Images::generateThumbnails方法的典型用法代碼示例。如果您正苦於以下問題:PHP Images::generateThumbnails方法的具體用法?PHP Images::generateThumbnails怎麽用?PHP Images::generateThumbnails使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Images
的用法示例。
在下文中一共展示了Images::generateThumbnails方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: executeEdit
/**
* Executes edit action.
*/
public function executeEdit()
{
// populate objects for form display depending on what we are doing (creating, editing)
$this->setEditFormInformation();
// All modules will use the same template
$this->setTemplate('../../documents/templates/edit');
$document = $this->document;
$module_name = $this->getModuleName();
$this->document_name = $document->get('name');
// Culture (lang) is automatically defined in Hydrate,
// redefined in the model.
if ($this->getRequest()->getMethod() == sfRequest::POST) {
$lang = $this->getRequestParameter('lang');
$user_id = $this->getUser()->getId();
$is_minor = $this->getRequestParameter('rev_is_minor', false);
$message = $this->getRequestParameter('rev_comment');
$document->setCulture($lang);
$old_lon = $document->get('lon');
$old_lat = $document->get('lat');
$this->setDataFields($document);
// upload potential GPX file to server and set WKT field
// or upload a new version of an image
$request = $this->getRequest();
if ($request->hasFiles()) {
c2cTools::log('request has files');
if ($request->getFileName('image_new_version') && $module_name == 'images') {
c2cTools::log('new image uploaded');
$base_path = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR;
$temp_dir = $base_path . sfConfig::get('app_images_temp_directory_name');
$upload_dir = $base_path . sfConfig::get('app_images_directory_name');
$filename = $request->getFiles();
$unique_filename = c2cTools::generateUniqueName();
$file_ext = Images::detectExtension($filename['image_new_version']['tmp_name']);
// upload file in a temporary folder
$new_location = $temp_dir . DIRECTORY_SEPARATOR . $unique_filename . $file_ext;
sfLoader::loadHelpers(array('General'));
$redir_route = '@document_by_id_lang_slug?module=' . $module_name . '&id=' . $this->document->get('id') . '&lang=' . $this->document->getCulture() . '&slug=' . get_slug($this->document);
if (!$request->moveFile('image_new_version', $new_location)) {
return $this->setErrorAndRedirect('Failed moving uploaded file', $redir_route);
}
if ($file_ext == '.svg') {
if (!SVG::rasterize($temp_dir . DIRECTORY_SEPARATOR, $unique_filename, $file_ext)) {
return $this->setErrorAndRedirect('Failed rasterizing svg file', $redir_route);
}
$document->set('has_svg', true);
} else {
$document->set('has_svg', false);
}
// generate thumbnails (ie. resized images: "BI"/"SI")
Images::generateThumbnails($unique_filename, $file_ext, $temp_dir);
// move to uploaded images directory
if (!Images::moveAll($unique_filename . $file_ext, $temp_dir, $upload_dir)) {
return $this->setErrorAndRedirect('image dir unavailable', $redir_route);
}
// update filename and image properties
$document->set('filename', $unique_filename . $file_ext);
$size = getimagesize($upload_dir . DIRECTORY_SEPARATOR . $unique_filename . $file_ext);
if ($size) {
$document->set('width', $size[0]);
$document->set('height', $size[1]);
}
$document->set('file_size', filesize($upload_dir . DIRECTORY_SEPARATOR . $unique_filename . $file_ext));
// populate with new exif data, if any...
$document->populateWithExifDataFrom($upload_dir . DIRECTORY_SEPARATOR . $unique_filename . $file_ext);
}
if ($request->getFileName('gps_data') && in_array($module_name, array('routes', 'outings'))) {
// it is necessary to preserve both tests nested.
if ($wkt = $this->getWktFromFileUpload($request)) {
c2cTools::log('wkt extracted');
$document->set('geom_wkt', $wkt);
// NB: these fields exist in both objects for which a file upload is possible (outings, routes)
$_a = ParseGeo::getCumulatedHeightDiffFromWkt($wkt);
if (!$document->get('height_diff_up')) {
$document->set('height_diff_up', $_a['up']);
c2cTools::log('height diff up set from wkt : ' . $_a['up']);
}
if (!$document->get('height_diff_down')) {
$document->set('height_diff_down', $_a['down']);
c2cTools::log('height diff down set from wkt : ' . $_a['down']);
}
$message = '[geodata] ' . (!$message ? "Edit with geometry upload" : $message);
} else {
$this->getRequest()->setError('gps_data', 'invalid gpx file');
return false;
}
}
}
if (count($this->document->getModified()) == 0 && count($this->document->getCurrentI18nObject()->getModified()) == 0) {
// no change of the document was detected
// => redirects to the document without saving anything
$this->redirectToView();
return;
}
// we prevent here concurrent edition :
// fake data so that second test always fails on summit creation (and when document is an archive) :
$rev_when_edition_begun = 1;
$current_rev = 0;
//.........這裏部分代碼省略.........
示例2: handleImage
private function handleImage($image_name, $tmp_name, $temp_dir, $index = 1)
{
// copy the image to the temp directory
$filename = $tmp_name;
$unique_filename = c2cTools::generateUniqueName();
$file_ext = Images::detectExtension($filename);
$new_location = $temp_dir . $unique_filename . $file_ext;
if (!move_uploaded_file($filename, $new_location)) {
return array('error' => array('field' => 'image_file', 'msg' => 'Failed moving uploaded file'));
}
// svg
if ($file_ext == '.svg') {
if (!SVG::rasterize($temp_dir, $unique_filename, $file_ext)) {
return array('error' => array('field' => 'image_file', 'msg' => 'Failed rasterizing svg file'));
}
}
// if jpg, check if we need orientation changes
if ($file_ext == '.jpg') {
Images::correctOrientation($new_location);
}
// generate thumbnails
Images::generateThumbnails($unique_filename, $file_ext, $temp_dir);
// look iptc for a possible title (jpeg only)
if ($file_ext == '.jpg') {
$size = getimagesize($new_location, $info);
if (isset($info['APP13'])) {
$iptc = iptcparse($info['APP13']);
if (isset($iptc['2#105'])) {
$image_title = trim($iptc['2#105'][0]);
} else {
if (isset($iptc['2#120'])) {
$image_title = trim($iptc['2#120'][0]);
}
}
}
}
if (isset($image_title)) {
$encoding = mb_detect_encoding($image_title, "UTF-8, ISO-8859-1, ISO-8859-15", true);
if ($encoding !== false) {
if ($encoding != 'UTF-8') {
$image_title = mb_convert_encoding($image_title, 'UTF-8', $encoding);
} else {
$image_title = $image_title;
}
}
// if encoding could not be detected, rather not try to put it as prefilled title
}
// we are also interested at this point on the exif date in order to reorder images on the client side
if ($file_ext == '.jpg' && ($exif = exif_read_data($new_location))) {
if (isset($exif['DateTimeOriginal'])) {
$image_date = str_replace(' ', ':', $exif['DateTimeOriginal']);
$image_date = explode(':', $image_date);
$image_date = mktime($image_date[3], $image_date[4], $image_date[5], $image_date[1], $image_date[2], $image_date[0]);
}
}
return array('image_filename' => $unique_filename . $file_ext, 'default_license' => $this->getDefaultImageLicense($this->getRequestParameter('document_id'), $this->getRequestParameter('mod')), 'image_number' => (intval($this->getRequestparameter('image_number')) + 1) * 1000 + $index, 'image_title' => isset($image_title) ? $image_title : null, 'image_datetime' => isset($image_date) && $image_date ? $image_date : null);
}