Skip to content

Commit

Permalink
CS-5603: Media Archive thumbnails are square, should be landscape or …
Browse files Browse the repository at this point in the history
…portrait

fix regression.
  • Loading branch information
Paweł Mikołajczuk committed Jan 12, 2015
1 parent 49a3613 commit 8731840
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions newscoop/library/Newscoop/Image/ImageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct(array $config, \Doctrine\ORM\EntityManager $orm, $ca
*
* @return LocalImage
*/
public function upload(UploadedFile $file, array $attributes, ImageInterface $image = null)
public function upload(UploadedFile $file, array $attributes, ImageInterface $image = null, $keepRatio = true)
{
$filesystem = new Filesystem();
$imagine = new Imagine();
Expand Down Expand Up @@ -119,8 +119,23 @@ public function upload(UploadedFile $file, array $attributes, ImageInterface $im
$file->move($this->config['image_path'], $this->generateImagePath($image->getId(), $file->getClientOriginalExtension(), true));
$filesystem->chmod($imagePath, 0644);

if ($keepRatio) {
$ratioOrig = $width / $height;
$ratioNew = $this->config['thumbnail_max_size'] / $this->config['thumbnail_max_size'];
if ($ratioNew > $ratioOrig) {
$newImageWidth = $this->config['thumbnail_max_size'] * $ratioOrig;
$newImageHeight = $this->config['thumbnail_max_size'];
} else {
$newImageWidth = $this->config['thumbnail_max_size'];
$newImageHeight = $this->config['thumbnail_max_size'] / $ratioOrig;
}
} else {
$newImageWidth = $this->config['thumbnail_max_size'];
$newImageHeight = $this->config['thumbnail_max_size'];
}

$imagine->open($imagePath)
->resize(new Box($this->config['thumbnail_max_size'], $this->config['thumbnail_max_size']))
->resize(new Box($newImageWidth, $newImageHeight))
->save($thumbnailPath, array());
$filesystem->chmod($thumbnailPath, 0644);
} catch (\Exceptiom $e) {
Expand Down Expand Up @@ -293,29 +308,24 @@ private function generateImagePath($imageId, $extension, $olnyFileName = false)
public function fillImage($image, $attributes)
{
$attributes = array_merge(array(
'description' => '',
'photographer' => '',
'photographer_url' => '',
'place' => '',
'date' => date('Y-m-d'),
'content_type' => 'image/jeg',
'content_type' => 'image/jpeg',
'user' => null,
'updated' => new \DateTime(),
'status' => 'unapproved',
'source' => 'local',
'url' => ''
), $attributes);

$image->setDescription($attributes['description']);
$image->setPhotographer($attributes['photographer']);
$image->setPhotographerUrl($attributes['photographer_url']);
$image->setPlace($attributes['place']);
if (isset($attributes['description'])) { $image->setDescription($attributes['description']); }
if (isset($attributes['photographer'])) { $image->setPhotographer($attributes['photographer']); }
if (isset($attributes['photographer_url'])) { $image->setPhotographerUrl($attributes['photographer_url']); }
if (isset($attributes['place'])) { $image->setPlace($attributes['place']); }
$image->setDate($attributes['date']);
$image->setContentType($attributes['content_type']);
$image->setUser($attributes['user']);
$image->setUpdated($attributes['updated']);
$image->setSource($attributes['source']);
$image->setUrl($attributes['url']);
if (isset($attributes['url'])) { $image->setUrl($attributes['url']); }

if ($image->getUser() && $image->getUser()->isAdmin() == true) {
$image->setStatus('approved');
Expand Down Expand Up @@ -466,12 +476,9 @@ public function getDefaultArticleImage($articleNumber)
));

if ($image === null) {
$image = array_pop(
$this->orm->getRepository('Newscoop\Image\ArticleImage')->findBy(
array('articleNumber' => (int) $articleNumber),
array('number' => 'asc'),
1
)
$image = $this->orm->getRepository('Newscoop\Image\ArticleImage')->findOneBy(
array('articleNumber' => (int) $articleNumber),
array('number' => 'asc')
);

if ($image !== null) {
Expand Down

0 comments on commit 8731840

Please sign in to comment.