Created
January 24, 2013 18:16
-
-
Save staylor/4625955 to your computer and use it in GitHub Desktop.
Construct eMusic Image URLs by convention
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Convenience Method to construct Artist Image URL | |
* | |
* @param int $id | |
* @return string Returns URL for Artist Image | |
*/ | |
function artist_image_url( $id ) { | |
$one = substr( $id, 0, 3 ); | |
$two = substr( $id, 3, 3 ); | |
if ( (int) $id < 10000000 ) { | |
$one = '0'; | |
$two = '0'; | |
} | |
$https = is_ssl() ? 's' : ''; | |
return sprintf( 'http%s://images.emusic.com/img/artist/%s/%s/%s.jpg', $https, $one, $two, $id ); | |
} | |
/** | |
* Convenience Method to construct Album Image URL | |
* | |
* @param int $id ALbum ID | |
* @return string Returns URL for Album Image | |
*/ | |
function album_image_url( $id ) { | |
$one = substr( $id, 0, 3 ); | |
$two = substr( $id, 3, 3 ); | |
$https = is_ssl() ? 's' : ''; | |
return sprintf( 'http%s://images.emusic.com/music/images/album/%s/%s/%s/300x300.jpg', $https, $one, $two, $id ); | |
} | |
/** | |
* Convenience Method to construct Book Image URL | |
* | |
* @param int $id | |
* @return string Returns URL for Book Image | |
*/ | |
function book_image_url( $id ) { | |
$one = substr( $id, 0, 3 ); | |
$two = substr( $id, 3, 3 ); | |
$https = is_ssl() ? 's' : ''; | |
return sprintf( 'http%s://images.emusic.com/books/images/book/0/%s/%s/%s/300x300.jpg', $https, $one, $two, $id ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment