/**
  * Get the cover image of the supplied object
  * @since Version 3.9.1
  * @param object $Object
  * @return array
  */
 public static function getCoverImageOfObject($Object)
 {
     if (!self::hasCoverImage($Object)) {
         return false;
     }
     $cachekey = sprintf("railpage:%s=%d;coverimage", $Object->namespace, $Object->id);
     $Memcached = AppCore::getMemcached();
     $Redis = AppCore::GetRedis();
     #printArray($cachekey);die;
     if ($result = $Memcached->fetch($cachekey)) {
         return $result;
     }
     if ($result = $Redis->fetch($cachekey)) {
         return $result;
     }
     $photoidvar = isset($Object->flickr_image_id) ? "flickr_image_id" : "photo_id";
     if (isset($Object->meta['coverimage'])) {
         $Image = ImageFactory::CreateImage($Object->meta['coverimage']['id']);
     } elseif ($Object->Asset instanceof Asset) {
         $Image = $Object->Asset;
     } elseif (isset($Object->{$photoidvar}) && filter_var($Object->{$photoidvar}, FILTER_VALIDATE_INT) && $Object->{$photoidvar} > 0) {
         $Image = ImageFactory::CreateImage($Object->{$photoidvar}, "flickr");
     }
     $return = array("type" => "image", "provider" => $Image instanceof Image ? $Image->provider : "", "title" => $Image instanceof Image ? $Image->title : $Asset->meta['title'], "author" => array("id" => "", "username" => "", "realname" => "", "url" => ""));
     if ($Image instanceof Image) {
         $return = array_merge($return, array("author" => array("id" => $Image->author->id, "username" => $Image->author->username, "realname" => isset($Image->author->realname) ? $Image->author->realname : $Image->author->username, "url" => $Image->author->url), "image" => array("id" => $Image->id), "sizes" => $Image->sizes, "url" => $Image->url->getURLs()));
     }
     if ($Object->Asset instanceof Asset) {
         $return = array_merge($return, array("sizes" => array("large" => array("source" => $Asset->meta['image']), "original" => array("source" => $Asset->meta['original'])), "url" => array("url" => $Asset['meta']['image'])));
     }
     $Memcached->save($cachekey, $return, strtotime("+1 hour"));
     $Redis->save($cachekey, $return, strtotime("+1 hour"));
     return $return;
 }
Exemple #2
0
 /**
  * Get EXIF data from an image
  * @since Version 3.10.0
  * @param \Railpage\Images\Image $imageObject
  * @param boolean $force
  * @return array
  */
 public function getImageExif(Image $imageObject, $force = false)
 {
     Debug::LogCLI("Fetching EIXF data for image ID " . $imageObject->id);
     if (!$force && isset($imageObject->meta['exif']) && $imageObject->meta['exif_format_version'] >= self::EXIF_FORMAT_VERSION) {
         $imageObject->meta['exif']['camera_make'] = self::normaliseCameraMake($imageObject->meta['exif']['camera_make']);
         $imageObject->meta['exif']['camera_model'] = self::normaliseCameraModel($imageObject->meta['exif']['camera_model']);
         $imageObject->meta['exif']['camera'] = ImageFactory::CreateCamera($imageObject->meta['exif']['camera_id'])->getArray();
         return $imageObject->meta['exif'];
     }
     /**
      * Fetch EXIF from the image provider API
      */
     $Provider = $imageObject->getProvider();
     $exif = $Provider->getExif($imageObject->photo_id);
     $exif_formatted = $this->getExifIDs($exif);
     $imageObject->meta['exif'] = $exif_formatted;
     $imageObject->meta['exif_format_version'] = self::EXIF_FORMAT_VERSION;
     $imageObject->commit();
     /**
      * Insert into our database
      */
     $query = "INSERT INTO image_exif ( \r\n                      image_id, camera_id, lens_id, lens_sn_id,\r\n                      aperture, exposure_id, exposure_program_id, \r\n                      focal_length, iso, white_balance_id\r\n                  ) VALUES (\r\n                      %d, %d, %d, %d, \r\n                      %s, %d, %d, \r\n                      %s, %s, %s\r\n                  ) ON DUPLICATE KEY UPDATE\r\n                      camera_id = VALUES(camera_id), lens_id = VALUES(lens_id),\r\n                      lens_sn_id = VALUES(lens_sn_id), aperture = VALUES(aperture),\r\n                      exposure_id = VALUES(exposure_id), exposure_program_id = VALUES(exposure_program_id),\r\n                      focal_length = VALUES(focal_length), iso = VALUES(iso), \r\n                      white_balance_id = VALUES(white_balance_id)";
     $query = sprintf($query, $this->db->quote($imageObject->id), $this->db->quote($exif_formatted['camera_id']), $this->db->quote($exif_formatted['lens_id']), $this->db->quote($exif_formatted['lens_sn_id']), $this->db->quote($exif_formatted['aperture']), $this->db->quote($exif_formatted['exposure_id']), $this->db->quote($exif_formatted['exposure_program_id']), $this->db->quote($exif_formatted['focal_length']), $this->db->quote($exif_formatted['iso_speed']), $this->db->quote($exif_formatted['white_balance_id']));
     $this->db->query($query);
     return $exif_formatted;
 }
Exemple #3
0
 public function test_fetchFlickr()
 {
     $Image = (new Images())->getImageFromUrl("https://www.flickr.com/photos/raichase/18184061975/", Images::OPT_REFRESH);
     $this->assertEquals("CSR001 Passing Crystal Brook", $Image->title);
     $this->assertEquals("flickr", $Image->provider);
     $this->assertFalse(!filter_var($Image->id, FILTER_VALIDATE_INT));
     $New = ImageFactory::CreateImage($Image->id);
     return $Image;
 }
 /**
  * @depends test_createPhotos
  */
 public function test_createCollage()
 {
     $Collage = new Collage();
     $Collage->setDimensions(600, 800)->setDimensions(320, 240);
     foreach ($this->ids as $id) {
         $Image = ImageFactory::CreateImage($id, "flickr");
         $Collage->addImage($Image);
     }
     $Collage->__toString();
 }
 /**
  * Get a single photo from this competition
  * @since Version 3.9.1
  * @return stdClass
  * @param array|\Railpage\Images\Image $image
  */
 public function getPhoto($image)
 {
     if (is_array($image) && !isset($image['status'])) {
         $query = "SELECT * FROM image_competition_submissions WHERE competition_id = ? AND image_id = ? ORDER BY date_added DESC";
         $params = array($this->id, $image['id']);
         $image = array_merge($this->db->fetchRow($query, $params), $image);
     }
     if ($image instanceof Image) {
         $query = "SELECT * FROM image_competition_submissions WHERE competition_id = ? AND image_id = ? ORDER BY date_added DESC";
         $params = array($this->id, $image->id);
         $image = $this->db->fetchRow($query, $params);
     }
     $Photo = new stdClass();
     $Photo->id = $image['id'];
     $Photo->Author = UserFactory::CreateUser($image['user_id']);
     $Photo->Image = ImageFactory::CreateImage(isset($image['image_id']) ? $image['image_id'] : $image['id']);
     $Photo->Meta = isset($image['meta']) ? json_decode($image['meta'], true) : [];
     $Photo->status = intval($image['status']);
     if (isset($image['date_added'])) {
         $Photo->DateAdded = new DateTime($image['date_added']);
     }
     if (isset($image['dateadded']['absolute'])) {
         $Photo->DateAdded = new DateTime($image['dateadded']['absolute']);
     }
     $Photo->url = new Url(sprintf("%s/%d", $this->url->url, $Photo->Image->id));
     $Photo->url->vote = sprintf("%s/vote", $Photo->url);
     return $Photo;
 }
Exemple #6
0
 /**
  * Get the cover photo attached to this thread
  * @since Version 3.10.0
  * @return \Railpage\Images\Image
  */
 public function getCoverPhoto()
 {
     if (isset($this->meta['coverphoto']) && filter_var($this->meta['coverphoto'], FILTER_VALIDATE_INT)) {
         $Image = ImageFactory::CreateImage($this->meta['coverphoto']);
         return $Image;
     }
     return false;
 }
Exemple #7
0
 /**
  * Fetch the latest information on an album from the relevant provider
  * @since Version 3.10.0
  * @param array $album
  * @return void
  */
 public static function ScrapeAlbum($album)
 {
     Debug::LogCLI("Scraping album ID " . $album['album_id'] . " from provider " . $album['provider']);
     set_time_limit(30);
     $Database = AppCore::GetDatabase();
     $Provider = ImageUtility::CreateImageProvider($album['provider']);
     // Assume Flickr for now, we can update the internal code later
     $params = ["photoset_id" => $album['album_id']];
     $albumdata = $Provider->execute("flickr.photosets.getInfo", $params);
     // Insert this shit into the database
     $data = ["scraped" => new Zend_Db_Expr("NOW()"), "meta" => json_encode($albumdata['photoset'])];
     $where = ["id = ?" => $album['id']];
     $Database->update("image_scrape_album", $data, $where);
     // Fetch the photos
     $params['user_id'] = $albumdata['photoset']['owner'];
     $photos = $Provider->execute("flickr.photosets.getPhotos", $params);
     foreach ($photos['photoset']['photo'] as $photo) {
         Debug::LogCLI("Scraping photo ID " . $photo['id']);
         set_time_limit(10);
         ImageFactory::CreateImage($photo['id'], $album['provider']);
         Debug::LogCLI("Sleeping for 2 seconds...");
         sleep(2);
     }
 }
Exemple #8
0
 /**
  * Find and set the hero image
  * @since Version 3.10.0
  * @return \Railpage\Newsletters\Weekly
  */
 private function getHeroImage()
 {
     $query = "SELECT f.image_id, i.meta FROM image_flags AS f LEFT JOIN image AS i ON f.image_id = i.id WHERE f.screened_pick = 1";
     $ids = [];
     foreach ($this->db->fetchAll($query) as $row) {
         $row['meta'] = json_decode($row['meta'], true);
         $sizes = Images::normaliseSizes($row['meta']['sizes']);
         if ($sizes['medium']['height'] > $sizes['medium']['width']) {
             continue;
         }
         $ids[] = $row['image_id'];
     }
     $image_id = $ids[array_rand($ids)];
     if (filter_var($image_id, FILTER_VALIDATE_INT)) {
         Debug::LogCLI("Creating instance of Image for the hero photo");
         $this->HeroImage = ImageFactory::CreateImage($image_id);
         $this->Newsletter->setHeroImage($this->HeroImage);
     }
     return $this;
 }