Skip to content

Commit

Permalink
fix function fails if there are no sizes in db.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Wong committed Jul 27, 2012
1 parent ecb16a6 commit bdd9993
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Extensions/WordpressTwigExtension.php
Expand Up @@ -202,6 +202,8 @@ public function getThumbnail(Post $post, $size = 'thumbnail', $keepRatio = false

$basename = $this->basename($thumbnail->getGuid());
$nearestSize = $this->getNearestSize($thumbnail, $size, $keepRatio);

if ($nearestSize === null) return null;

return str_replace($basename, $nearestSize['file'], $thumbnail->getGuid());
}
Expand All @@ -225,6 +227,8 @@ private function getNearestSize($attachment, $target = array(300, 200), $keepRat

list($x1, $y1) = $target;

if (!$allSizes) return null;

do {
foreach ($allSizes as $key => $size) {
$x2 = $size['width'];
Expand Down Expand Up @@ -260,7 +264,10 @@ private function getAllSizes($attachment)
'file' => $this->basename($attachment->getGuid()),
);

$allSizes = $metadata['sizes'];
if (array_key_exists('sizes', $metadata)){
$allSizes = $metadata['sizes'];
}

$allSizes['original'] = $originalSize;

return $allSizes;
Expand Down

0 comments on commit bdd9993

Please sign in to comment.