Пример #1
0
 /**
  * @covers Core\Helpers\Image::createCroppedThumbnail
  */
 public function testCroppedThumbnailSizeMatches()
 {
     $thumbnails = Image::createCroppedThumbnail($this->imagePath, $this->size);
     for ($i = 0; $i < count($thumbnails); $i++) {
         /* Get expected image size. */
         preg_match_all('/(\\d+)/', $this->size[$i], $expected);
         $expected = array_map('intval', $expected[0]);
         /* Get actual image size. */
         $actual = getimagesize($thumbnails[$i]);
         $actual = array_slice($actual, 0, 2);
         $this->assertEquals($expected, $actual);
     }
 }
Пример #2
0
 /**
  * Create all related file thumbnails.
  *
  * @param Base\Model $resource            Currently processed resource.
  * @param string     $name                Name of the thumbnail.
  * @param string     $attachment_filename Attachment file name.
  * @param array      $thumbnails          Array of thumbnail sizes.
  *
  * @access private
  * @static
  *
  * @return void
  */
 private static function createThumbnails(Base\Model $resource, $name, $attachment_filename, array $thumbnails)
 {
     foreach ($thumbnails as $thumbnail) {
         try {
             switch ($thumbnail['type']) {
                 case 'resize':
                     Helpers\Image::createScaledThumbnail($resource->attachmentsStoragePath($name) . $attachment_filename, array($thumbnail['size']));
                     break;
                 case 'crop':
                     Helpers\Image::createCroppedThumbnail($resource->attachmentsStoragePath($name) . $attachment_filename, array($thumbnail['size']));
                     break;
             }
         } catch (\Exception $e) {
             var_log($e->getMessage());
         }
     }
 }