本文整理汇总了PHP中Image::getHeight方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::getHeight方法的具体用法?PHP Image::getHeight怎么用?PHP Image::getHeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image::getHeight方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addTag
function addTag($srcPath, $dstPath)
{
$srcImage = new Image($srcPath);
$tagImagePath = CODE_ROOT_DIR . "uploads/custom/" . Config::get("watermarkImageSrc");
if (!file_exists($tagImagePath)) {
return;
}
$tagImage = new Image($tagImagePath);
list($posV, $posH) = explode(",", Config::get("imageWatermarkPosition"));
$tagMarginH = 5;
$tagMarginV = 5;
if ($posH == "l") {
$tagPositionX = 0 + $tagMarginH;
} else {
$tagPositionX = max($srcImage->getWidth() - $tagImage->getWidth() - $tagMarginH, 0);
}
if ($posV == "t") {
$tagPositionY = 0 + $tagMarginV;
} else {
$tagPositionY = max($srcImage->getHeight() - $tagImage->getHeight() - $tagMarginV, 0);
}
imagecopyresampled($srcImage->im, $tagImage->im, $tagPositionX, $tagPositionY, 0, 0, $tagImage->getWidth(), $tagImage->getHeight(), $tagImage->getWidth(), $tagImage->getHeight());
$srcImage->setPath($dstPath);
$srcImage->saveToFile();
}
示例2: imageResize
static public function imageResize($fname,$width,$height) {
$i = new Image( $fname );
$owhr=$i->getWidth()/$i->getHeight();
$twhr=$width/$height;
if( $owhr==$twhr ) {
$i->resize( $width,$height );
} elseif( $owhr>$twhr ) {
$i->resizeToHeight( $height );
$i->crop( ($i->getWidth()-$width)/2, 0, $width, $height);
} else {
$i->resizeToWidth( $width );
$i->crop( 0, ($i->getHeight()-$height)/2, $width, $height);
}
$i->save();
}
示例3: readFolder
public function readFolder()
{
$folder = $this->customer->getFolderName();
$dir = DIR_IMAGE . "catalog/" . $folder;
$allfiles = scandir($dir);
$img_links = array();
$counting = 0;
foreach ($allfiles as $image) {
//if the file is not hidden get the the URI
if (substr($image, 0, 1) != '.') {
//Once we get certified the config.php needs to be modified.
$modify_image = new Image(DIR_IMAGE . "catalog/" . $folder . "/" . $image);
// $mark = new Image(DIR_IMAGE. "logo.png");
$width = $modify_image->getWidth() * 0.2;
$height = $modify_image->getHeight() * 0.2;
// $mark->resize($width, $height);
// $modify_image->watermark($mark);
$size = $width * $height;
$modify_image->save($modify_image->getFile());
$img_links[$counting]['source'] = HTTPS_SERVER . "/image/catalog/" . $folder . "/" . $image;
$img_links[$counting]['width'] = $modify_image->getWidth();
$img_links[$counting]['height'] = $modify_image->getHeight();
$counting++;
}
}
return $img_links;
}
示例4: resize
/**
* @param string $filename
* @param int $width
* @param int $height
* @return string
*/
public function resize($filename, $width, $height)
{
if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) {
return null;
}
$info = pathinfo($filename);
$extension = $info['extension'];
$old_image = $filename;
try {
$image = new Image(DIR_IMAGE . $old_image);
} catch (Exception $exc) {
$image = new Image(DIR_IMAGE . 'no_image.jpg');
}
/// Ensure target size doesn't exceed original size
$ratio = $image->getWidth() / $image->getHeight();
$expectedHeight = round($width / $ratio);
$expectedWidth = round($height * $ratio);
if ($image->getWidth() >= $width) {
$targetWidth = $width;
$targetHeight = $expectedHeight;
} else {
$targetWidth = $image->getWidth();
$targetHeight = $image->getHeight();
}
if ($image->getHeight() < $targetHeight) {
$targetWidth = $expectedWidth;
$targetHeight = $image->getHeight();
}
$new_image = 'cache/' . substr($filename, 0, strrpos($filename, '.')) . '-' . $targetWidth . 'x' . $targetHeight . '.' . $extension;
if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) {
$path = '';
$directories = explode('/', dirname(str_replace('../', '', $new_image)));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!file_exists(DIR_IMAGE . $path)) {
@mkdir(DIR_IMAGE . $path, 0777);
}
}
$image->resize($targetWidth, $targetHeight);
$image->save(DIR_IMAGE . $new_image);
}
if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) {
return HTTPS_IMAGE . $new_image;
} else {
return HTTP_IMAGE . $new_image;
}
}
示例5: getImageAt
/**
* Resizes image by width or height only if the source image is bigger than the given width/height.
* This prevents ugly upscaling.
*
* @param int $width [optional]
* @param int $height [optional]
* @param bool $upscale [optional]
*
* @return Image
*/
public function getImageAt($width = null, $height = null, $upscale = false)
{
if (!$this->owner->exists()) {
return $this->owner;
}
$realWidth = $this->owner->getWidth();
$realHeight = $this->owner->getHeight();
if ($width && $height) {
return $realWidth < $width && $realHeight < $height && !$upscale ? $this->owner : $this->owner->Fit($width, $height);
} else {
if ($width) {
return $realWidth < $width && !$upscale ? $this->owner : $this->owner->ScaleWidth($width);
} else {
return $realHeight < $height && !$upscale ? $this->owner : $this->owner->ScaleHeight($height);
}
}
}
示例6: setProperties
/**
* Sets the objects properties
*
* @param $percentage float The percentage that the merge image should take up.
*/
protected function setProperties($percentage)
{
if ($percentage > 1) {
throw new \InvalidArgumentException('$percentage must be less than 1');
}
$this->sourceImageHeight = $this->sourceImage->getHeight();
$this->sourceImageWidth = $this->sourceImage->getWidth();
$this->mergeImageHeight = $this->mergeImage->getHeight();
$this->mergeImageWidth = $this->mergeImage->getWidth();
$this->calculateOverlap($percentage);
$this->calculateCenter();
}
示例7: setProperties
/**
* Sets the objects properties
*
* @param $percentage float The percentage that the merge image should take up.
*/
protected function setProperties($percentage)
{
if ($percentage > 1) {
throw new \InvalidArgumentException('$percentage must be less than 1');
}
$this->sourceHeight = $this->sourceImage->getHeight();
$this->sourceWidth = $this->sourceImage->getWidth();
$this->mergeHeight = $this->mergeImage->getHeight();
$this->mergeWidth = $this->mergeImage->getWidth();
$this->postMergeHeight = $this->mergeHeight * $percentage;
$this->postMergeWidth = $this->mergeWidth * $percentage;
$this->mergePosHeight = $this->sourceHeight / 2 - $this->postMergeHeight / 2;
$this->mergePosWidth = $this->sourceWidth / 2 - $this->postMergeHeight / 2;
}
示例8: handleOverview
/**
* handle overview request
*/
private function handleOverview()
{
$request = Request::getInstance();
$view = ViewManager::getInstance();
$page = $this->getPage();
$this->pagerUrl->setParameter($view->getUrlId(), $view->getType());
$taglist = $this->plugin->getTagList(array('plugin_type' => News::TYPE_ARCHIVE));
if (!$taglist) {
return;
}
$tree = $this->director->tree;
$url = new Url(true);
$url->setParameter($view->getUrlId(), News::VIEW_DETAIL);
// link to news tree nodes
$treeRef = new NewsTreeRef();
foreach ($taglist as $item) {
$template = new TemplateEngine($this->getPath() . "templates/" . $this->templateFile);
$template->setPostfix($item['tag']);
$template->setCacheable(true);
// check if template is in cache
if (!$template->isCached()) {
// get settings
$settings = $this->getSettings();
$key = array('tree_id' => $item['tree_id'], 'tag' => $item['tag']);
$detail = $this->getDetail($key);
$treeRefList = $treeRef->getList($key);
$treeItemList = array();
foreach ($treeRefList['data'] as $treeRefItem) {
if (!$tree->exists($treeRefItem['ref_tree_id'])) {
continue;
}
$treeItemList[] = $treeRefItem['ref_tree_id'];
}
if (!$treeItemList) {
continue;
}
$searchcriteria = array('tree_id' => $treeItemList, 'active' => true);
if ($detail['online']) {
$searchcriteria['archiveonline'] = $detail['online'];
}
$searchcriteria['archiveoffline'] = $detail['offline'] ? $detail['offline'] : time();
$overview = $this->getNewsOverview();
$list = $overview->getList($searchcriteria, $settings['rows'], $page);
foreach ($list['data'] as &$newsitem) {
$url->setParameter('id', $newsitem['id']);
$newsitem['href_detail'] = $url->getUrl(true);
if ($newsitem['thumbnail']) {
$img = new Image($newsitem['thumbnail'], $this->plugin->getContentPath(true));
$newsitem['thumbnail'] = array('src' => $this->plugin->getContentPath(false) . $img->getFileName(false), 'width' => $img->getWidth(), 'height' => $img->getHeight());
}
}
$template->setVariable('news', $list);
$template->setVariable('display', $settings['display'], false);
}
$this->template[$item['tag']] = $template;
}
}
示例9: buildImage
/**
* Create a new image based on an image preset.
*
* @param array $actions An image preset array.
* @param Image $image Path of the source file.
* @param string $dst Path of the destination file.
* @throws \RuntimeException
* @return Image
*/
protected function buildImage($actions, Image $image, $dst)
{
foreach ($actions as $action) {
// Make sure the width and height are computed first so they can be used
// in relative x/yoffsets like 'center' or 'bottom'.
if (isset($action['width'])) {
$action['width'] = $this->percent($action['width'], $image->getWidth());
}
if (isset($action['height'])) {
$action['height'] = $this->percent($action['height'], $image->getHeight());
}
if (isset($action['xoffset'])) {
$action['xoffset'] = $this->keywords($action['xoffset'], $image->getWidth(), $action['width']);
}
if (isset($action['yoffset'])) {
$action['yoffset'] = $this->keywords($action['yoffset'], $image->getHeight(), $action['height']);
}
$this->getMethodCaller()->call($image, $action['action'], $action);
}
return $image->save($dst);
}
示例10: handleTreeEditGet
/**
* handle tree edit
*/
private function handleTreeEditGet($retrieveFields = true)
{
$template = new TemplateEngine($this->getPath() . "templates/" . $this->templateFile);
$request = Request::getInstance();
$view = ViewManager::getInstance();
$view->setType(Calendar::VIEW_IMAGE_EDIT);
$tree_id = intval($request->getValue('tree_id'));
$tag = $request->getValue('tag');
$template->setVariable('tree_id', $tree_id, false);
$template->setVariable('tag', $tag, false);
if (!$request->exists('id')) {
throw new Exception('Bestand is missing.');
}
$id = intval($request->getValue('id'));
$template->setVariable('id', $id, false);
$key = array('id' => $id);
if ($retrieveFields) {
$fields = $this->getDetail($key);
} else {
$fields = $this->getFields(SqlParser::MOD_UPDATE);
$detail = $this->getDetail($key);
$fields['file'] = $detail['file'];
}
$this->setFields($fields);
if ($fields['image']) {
$img = new Image($fields['image'], $this->plugin->getContentPath(true));
$fields['image'] = array('src' => $this->plugin->getContentPath(false) . $img->getFileName(false), 'width' => $img->getWidth(), 'height' => $img->getHeight());
}
$template->setVariable($fields);
$this->handleTreeSettings($template);
// get crop settings
$settings = $this->plugin->getSettings();
//only crop if both width and height defaults are set
if ($fields['image'] && $settings['image_width'] && $settings['image_height'] && ($fields['image']['width'] > $settings['image_width'] || $fields['image']['height'] > $settings['image_height'])) {
$theme = $this->director->theme;
$parseFile = new ParseFile();
$parseFile->setVariable($fields);
$parseFile->setVariable('imgTag', 'imgsrc');
$parseFile->setVariable($settings);
$parseFile->setSource($this->plugin->getHtdocsPath(true) . "js/cropinit.js.in");
//$parseFile->setDestination($this->plugin->getCachePath(true)."cropinit_tpl_content.js");
//$parseFile->save();
$theme->addJavascript($parseFile->fetch());
$theme->addHeader('<script type="text/javascript" src="' . DIF_VIRTUAL_WEB_ROOT . 'js/prototype.js"></script>');
$theme->addHeader('<script type="text/javascript" src="' . DIF_VIRTUAL_WEB_ROOT . 'js/scriptaculous.js"></script>');
$theme->addHeader('<script type="text/javascript" src="' . DIF_VIRTUAL_WEB_ROOT . 'js/cropper.js"></script>');
$theme->addHeader('<script type="text/javascript" src="' . DIF_VIRTUAL_WEB_ROOT . 'js/mint.js"></script>');
//$theme->addHeader('<script type="text/javascript" src="'.$this->plugin->getCachePath().'cropinit_tpl_content.js"></script>');
}
$this->template[$this->director->theme->getConfig()->main_tag] = $template;
}
示例11: handlePluginList
private function handlePluginList($tag, $parameters)
{
$template = new TemplateEngine($this->getPath() . "templates/" . $this->templateFile);
$request = Request::getInstance();
$view = ViewManager::getInstance();
$searchcriteria = isset($parameters) && array_key_exists('searchcriteria', $parameters) ? $parameters['searchcriteria'] : array();
$keys = isset($parameters) && array_key_exists('keys', $parameters) ? $parameters['keys'] : array();
$searchcriteria['id'] = $keys;
$settings = $this->plugin->getSettings();
$template->setVariable('settings', $settings);
$systemSite = new SystemSite();
$tree = $systemSite->getTree();
$list = $this->getList($searchcriteria, $pagesize, $page);
foreach ($list['data'] as &$item) {
//TODO get url from caller plugin (newsletter) to track visits
$url = new Url();
$url->setPath($request->getProtocol() . $request->getDomain() . $tree->getPath($item['tree_id']));
$url->setParameter('id', $item['id']);
$url->setParameter(ViewManager::URL_KEY_DEFAULT, Calendar::VIEW_DETAIL);
$item['href_detail'] = $url->getUrl(true);
if ($item['thumbnail']) {
$img = new Image($item['thumbnail'], $this->plugin->getContentPath(true));
$item['thumbnail'] = array('src' => $this->plugin->getContentPath(false) . $img->getFileName(false), 'width' => $img->getWidth(), 'height' => $img->getHeight());
}
}
$template->setVariable('calendar', $list);
$this->template[$tag] = $template;
}
示例12: insert
public function insert(Image $replacement, $x, $y, $width, $height)
{
imagecopyresized($this->handle, $replacement->getHandle(), $x, $y, 0, 0, $width, $height, $replacement->getWidth(), $replacement->getHeight());
return $this;
}
示例13: formatImage
protected function formatImage($image, $inCitation = false)
{
$filename = (string) $image['filename'];
if (!$filename) {
return '';
}
$caption = (string) $image['caption'];
$iconWidth = SearchForm::THUMB_WIDTH;
$iconHeight = 48;
$t = Title::makeTitle(NS_IMAGE, $filename);
if (!$t || !$t->exists()) {
return '';
}
$image = new Image($t);
$maxHoverWidth = 700;
$maxHoverHeight = 300;
$width = $image->getWidth();
$height = $image->getHeight();
if ($height > 0 && $maxHoverWidth > $width * $maxHoverHeight / $height) {
$maxHoverWidth = wfFitBoxWidth($width, $height, $maxHoverHeight);
}
$imageURL = $image->createThumb($maxHoverWidth, $maxHoverHeight);
$titleAttr = StructuredData::escapeXml("{$imageURL}|{$maxHoverWidth}");
if ($inCitation) {
return "<span class=\"wr-citation-image wr-imagehover inline-block\" title=\"{$titleAttr}\">{$caption} [[Image:{$filename}|{$iconWidth}x{$iconHeight}px]]</span>";
} else {
return "<span class=\"wr-imagehover inline-block\" title=\"{$titleAttr}\">[[Image:{$filename}|thumb|left|{$caption}]]</span>";
}
// return <<<END
//<div class="inline-block">
// <span id="$id">[[Image:$filename|thumb|left|$id. $caption]]</span>
//</div>
//END;
}
示例14: addAndResizeLayer
/**
* @param Image $src
* @param int $x
* @param int $y
* @param int $width
* @param int $height
* @return Image
*/
public function addAndResizeLayer(Image $src, $x, $y, $width, $height)
{
if ($src->getWidth() !== $width || $src->getHeight() !== $height) {
$src = $src->resizeTo($width, $height);
}
return $this->addLayer($src, $x, $y);
}
示例15: uploadAll
public function uploadAll()
{
$this->load->language('common/filemanager');
$error = array();
$extension = array("jpeg", "jpg", "png", "gif", "JPG", "bmp");
// Make sure we have the correct directory
if (isset($this->request->get['directory'])) {
$directory = rtrim(DIR_IMAGE . 'catalog/' . str_replace(array('../', '..\\', '..'), '', $this->request->get['directory']), '/');
} else {
$directory = DIR_IMAGE . 'catalog';
}
// Check it's a directory
if (!is_dir($directory)) {
$json['error'] = $this->language->get('error_directory');
}
$clientFolder = $this->request->get['directory'];
foreach ($this->request->files["file"]["tmp_name"] as $key => $tmp_name) {
$file_name = $this->request->files["file"]["name"][$key];
$file_name = str_replace(" ", "_", $file_name);
$file_tmp = $this->request->files["file"]["tmp_name"][$key];
$ext = pathinfo($file_name, PATHINFO_EXTENSION);
//Contruct the image object for modification
$new_image = new Image($file_tmp);
$w = $new_image->getWidth();
$h = $new_image->getHeight();
$size = $w * $h;
$new_image->resize($w * 0.5, $h * 0.5);
if (in_array($ext, $extension)) {
if (!file_exists($directory . "/" . $file_name)) {
//move_uploaded_file($file_tmp = $this->request->files["file"]["tmp_name"][$key], $directory . "/" . $file_name);
move_uploaded_file($new_image->getFile(), $directory . "/" . $file_name);
$json['success'] = 'Files are uploaded';
} else {
$json['error'] = 'Duplicate file error';
}
} else {
array_push($error, "{$file_name}, ");
$json['error'] = $this->language->get('error_upload');
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}