Example #1
0
function display_mini($photoid)
{
    $api = Phlickr_Api::createFrom(API_CONFIG_FILE);
    $p = new Phlickr_Photo($api, $photoid);
    $title = $p->getTitle();
    print '<small>' . $title . '</small><a href="' . $p->buildUrl() . '"><img src="' . $p->buildImgURL('t') . '" border="0" /></a>';
}
Example #2
0
    function testGetTaken_Granularity6()
    {
        $photo = new Phlickr_Photo($this->api, simplexml_load_string(<<<XML
<photo id="2733" secret="123456" server="12">
    <dates taken="2004-01-01 00:00:00" takengranularity="6" />
</photo>
XML
));
        $expected = mktime(0, 0, 0, 1, 1, 2004);
        $this->assertEquals(6, $photo->getTakenGranularity());
        $this->assertEquals($expected, $photo->getTakenTimestamp());
    }
Example #3
0
 /**
  * Return the photo's date for sorting.
  *
  * @param   object Phlickr_Photo $photo
  * @return  string
  */
 function stringFromPhoto(Phlickr_Photo $photo)
 {
     return $photo->getTakenDate();
 }
Example #4
0
 /**
  * Return the photo's title for sorting.
  *
  * @param   object Phlickr_Photo $photo
  * @return  string
  * @since   0.2.4
  */
 function stringFromPhoto(Phlickr_Photo $photo)
 {
     return $photo->getTitle();
 }
Example #5
0
    function testBuildImgUrl_OriginalSize()
    {
        // add the bare minimum response specifying the original size file type
        $this->api->addResponseToCache('flickr.photos.getSizes', Phlickr_Photo::getRequestMethodParams(TESTING_PHOTO_ID), TESTING_RESP_OK_PREFIX . <<<XML
<sizes>
    <size label="Original" width="1733" height="1146"
        source="http://static.flickr.com/22/24778503_7263862414_o.jpg"/>
    </sizes>
XML
 . TESTING_RESP_SUFIX);
        $result = $this->fromShortXml->buildImgUrl(Phlickr_Photo::SIZE_ORIGINAL);
        $this->assertEquals('http://static.flickr.com/12/2733_123456_o.jpg', $result);
    }
Example #6
0
 function testSaveAs_OriginalSize()
 {
     $photo = new Phlickr_Photo($this->api, '7836107');
     $photo->saveAs($this->filepath, Phlickr_Photo::SIZE_ORIGINAL);
     $this->assertTrue(file_exists($this->filepath));
     $sizes = getimagesize($this->filepath);
     $this->assertEquals(1536, $sizes[0], 'incorrect width');
     $this->assertEquals(2048, $sizes[1], 'incorrect height');
 }
Example #7
0
 /**
  * Constructor.
  *
  * You can construct a photo from an Id or XML.
  *
  * @param   object Phlickr_Api $api This object must have valid
  *          authentication information or an exception will be thrown.
  * @param   mixed $source string Id, object SimpleXMLElement
  * @throws  Phlickr_Exception, Phlickr_ConnectionException,
  *          Phlickr_XmlParseException
  */
 function __construct(Phlickr_Api $api, $source)
 {
     parent::__construct($api, $source);
 }
Example #8
0
 function testUpload_WithClassPermissions()
 {
     $this->uploader->setPerms(false, false, false);
     // upload it
     $result = $this->uploader->Upload(TESTING_FILE_NAME_JPG, 'testing title', 'a description', 'atag btag');
     // verify the returned id
     $this->assertType('string', $result, 'Returned the wrong type.');
     $photo = new Phlickr_Photo($this->api, $result);
     $this->assertFalse($photo->isForPublic());
     $this->assertFalse($photo->isForFriends());
     $this->assertFalse($photo->isForFamily());
 }
Example #9
0
 /**
  * Reformat the photo's id into a fixed width string that can be sorted.
  *
  * @param   object Phlickr_Photo $photo
  * @return  string
  */
 function stringFromPhoto(Phlickr_Photo $photo)
 {
     return sprintf('%012d', $photo->getId());
 }
Example #10
0
 /**
  * Return a sortable string of the photos average color.
  *
  * Steps:
  * -  Resample the image to single pixel.
  * -  Convert the pixel's RGB value to an HSV value,
  * -  Convert the HSV to a string.
  *
  * @param   object Phlickr_Photo $photo
  * @return  string or false in case of error.
  */
 public function stringFromPhoto(Phlickr_Photo $photo)
 {
     // cache the RGB value so that multiple color sort strategies can
     // share the average color.
     $key = 'avg_color:' . $photo->getId();
     if ($this->_cache->has($key)) {
         $rgb = $this->_cache->get($key);
     } else {
         $url = $photo->buildImgUrl(Phlickr_Photo::SIZE_100PX);
         if ($rgb = self::getAverageRgbColor($url)) {
             // add the average color to the cache and mark it as
             // non-expiring because the photo can't be changed.
             $this->_cache->set($key, $rgb, -1);
         } else {
             // if there's an error getting the average value don't add it
             // to the cache, just bail.
             return false;
         }
     }
     $hsv = self::HsvFromRgb($rgb);
     return sprintf("%02d,%02d,%02d", round($hsv[0] / 30), round($hsv[1] * 10), round($hsv[2] * 10));
 }