mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-06 03:49:56 +02:00
Add php-tmdb-api module
This commit is contained in:
parent
786c234d5f
commit
d5d84d6462
189 changed files with 20018 additions and 1 deletions
93
modules/Tmdb/Helper/ImageHelper.php
Normal file
93
modules/Tmdb/Helper/ImageHelper.php
Normal file
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of the Tmdb PHP API created by Michael Roterman.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @package Tmdb
|
||||
* @author Michael Roterman <michael@wtfz.net>
|
||||
* @copyright (c) 2013, Michael Roterman
|
||||
* @version 0.0.1
|
||||
*/
|
||||
namespace Tmdb\Helper;
|
||||
|
||||
use Tmdb\Model\Configuration;
|
||||
use Tmdb\Model\Image;
|
||||
|
||||
/**
|
||||
* Class ImageHelper
|
||||
* @package Tmdb\Helper
|
||||
*/
|
||||
class ImageHelper {
|
||||
|
||||
private $config;
|
||||
|
||||
public function __construct(Configuration $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the image configuration collection
|
||||
*
|
||||
* @return \Tmdb\Model\Common\GenericCollection
|
||||
*/
|
||||
public function getImageConfiguration()
|
||||
{
|
||||
return $this->config->getImages();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the url for the image resource
|
||||
*
|
||||
* @param Image $image
|
||||
* @param string $size
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl(Image $image, $size = 'original') {
|
||||
$config = $this->getImageConfiguration();
|
||||
|
||||
return $config['base_url'] . $size . $image->getFilePath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an img html tag for the image in the specified size
|
||||
*
|
||||
* @param Image $image
|
||||
* @param string $size
|
||||
* @param int|null $width
|
||||
* @param int|null $height
|
||||
* @return string
|
||||
*/
|
||||
public function getHtml(Image $image, $size = 'original', $width = null, $height = null) {
|
||||
if (null == $image->getFilePath()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$aspectRatio = $image->getAspectRatio();
|
||||
|
||||
if (null !== $width && null == $height && $aspectRatio !== null) {
|
||||
$height = round($width / $aspectRatio);
|
||||
}
|
||||
|
||||
if (null !== $height && null == $width && $aspectRatio !== null) {
|
||||
$width = round($height * $aspectRatio);
|
||||
}
|
||||
|
||||
if (null == $width) {
|
||||
$width = $image->getWidth();
|
||||
}
|
||||
|
||||
if (null == $height) {
|
||||
$height = $image->getHeight();
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
'<img src="%s" width="%s" height="%s" />',
|
||||
$this->getUrl($image, $size),
|
||||
$width,
|
||||
$height
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue