Example #1
0
 /**
  * getCoverArt
  * Get a cover art image.
  * Takes the cover art id in parameter.
  */
 public static function getcoverart($input)
 {
     self::check_version($input, "1.0.0", true);
     $id = self::check_parameter($input, 'id', true);
     $size = $input['size'];
     $art = null;
     if (Subsonic_XML_Data::isArtist($id)) {
         $art = new Art(Subsonic_XML_Data::getAmpacheId($id), "artist");
     } elseif (Subsonic_XML_Data::isAlbum($id)) {
         $art = new Art(Subsonic_XML_Data::getAmpacheId($id), "album");
     } elseif (Subsonic_XML_Data::isSong($id)) {
         $art = new Art(Subsonic_XML_Data::getAmpacheId($id), "song");
         if ($art != null && $art->id == null) {
             // in most cases the song doesn't have a picture, but the album where it belongs to has
             // if this is the case, we take the album art
             $song = new Song(Subsonic_XML_Data::getAmpacheId(Subsonic_XML_Data::getAmpacheId($id)));
             $art = new Art(Subsonic_XML_Data::getAmpacheId($song->album), "album");
         }
     } elseif (Subsonic_XML_Data::isPodcast($id)) {
         $art = new Art(Subsonic_XML_Data::getAmpacheId($id), "podcast");
     }
     header("Access-Control-Allow-Origin: *");
     if ($art != null) {
         $art->get_db();
         if ($size && AmpConfig::get('resize_images')) {
             $dim = array();
             $dim['width'] = $size;
             $dim['height'] = $size;
             $thumb = $art->get_thumb($dim);
             if ($thumb) {
                 header('Content-type: ' . $thumb['thumb_mime']);
                 header('Content-Length: ' . strlen($thumb['thumb']));
                 echo $thumb['thumb'];
                 return;
             }
         }
         header('Content-type: ' . $art->raw_mime);
         header('Content-Length: ' . strlen($art->raw));
         echo $art->raw;
     }
 }