Created
July 17, 2011 20:15
-
-
Save jocull/1088012 to your computer and use it in GitHub Desktop.
Cover art spread code
This file contains 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 | |
require_once('radio_functions.php'); | |
@dbconnect(); | |
ini_set('memory_limit', '512M'); | |
$limit = 0; | |
if(isset($_GET["limit"]) && is_numeric($_GET["limit"])) | |
$limit = $_GET["limit"]; | |
$until = 0; | |
if(isset($_GET["until"]) && is_numeric($_GET["until"])) | |
$until = $_GET["until"]; | |
$start = 0; | |
if(isset($_GET["start"]) && is_numeric($_GET["start"])) | |
$start = $_GET["start"]; | |
$end = 999999; | |
if(isset($_GET["end"]) && is_numeric($_GET["end"])) | |
$end = $_GET["end"]; | |
$shuffle = 1; | |
if(isset($_GET["shuffle"]) && $_GET["shuffle"] == 0) | |
$shuffle = 0; | |
$square = 300; | |
if(isset($_GET["square"]) && is_numeric($_GET["square"])) | |
$square = $_GET["square"]; | |
$width = 10; | |
if(isset($_GET["width"]) && is_numeric($_GET["width"])) | |
$width = $_GET["width"]; | |
$resample = false; | |
if(isset($_GET["resample"]) && $_GET["resample"] == 1) | |
$resample = true; | |
$type = "jpg"; | |
if(isset($_GET["type"]) && $_GET["type"] == "png") | |
$type = $_GET["type"]; | |
$jpgquality = 75; | |
if(isset($_GET["jpgquality"]) && is_numeric($_GET["jpgquality"]) && $_GET["jpgquality"] > 0 && $_GET["jpgquality"] <= 100) | |
$jpgquality = $_GET["jpgquality"]; | |
$pngquality = 0; | |
if(isset($_GET["pngquality"]) && is_numeric($_GET["pngquality"]) && $_GET["pngquality"] > 0 && $_GET["pngquality"] <= 9) | |
$pngquality = $_GET["pngquality"]; | |
$sql = "select filename, artist, album | |
from radio_files | |
where length(album) > 0 and length(artist) > 0 | |
group by artist, album | |
limit $start, $end"; | |
$result = mysql_query($sql,$connection); | |
$firstlist = array(); | |
while($track = mysql_fetch_assoc($result)) | |
array_push($firstlist, $track); | |
$list = array(); | |
foreach($firstlist as $row) | |
{ | |
$filepath = $row["filename"]; | |
$imgpath = ""; | |
if(file_exists(dirname($filepath)."/folder.jpg")) | |
$imgpath = dirname($filepath)."/folder.jpg"; | |
else if(file_exists(dirname($filepath)."/Folder.jpg")) | |
$imgpath = dirname($filepath)."/Folder.jpg"; | |
if($imgpath != "") | |
array_push($list, $imgpath); | |
} | |
$totalwidth = $square * $width; | |
$count = count($list); | |
if($limit > 0) | |
$count = $limit; | |
if($until > 0) | |
$count = $until; | |
$totalheight = ceil($count / $width) * $square; | |
$spread = imagecreatetruecolor($totalwidth, $totalheight); | |
$count = 1; | |
$pointerw = 0; | |
$pointerh = 0; | |
do{ | |
if($shuffle == 1) | |
shuffle($list); | |
foreach($list as $row) | |
{ | |
$imgpath = $row; | |
if($imgpath != "") | |
{ | |
$ext = substr(strrchr($imgpath, '.'), 1); | |
$image = NULL; | |
if(strtoupper($ext) == "JPG") | |
{ | |
$image = imagecreatefromjpeg($imgpath); | |
} | |
else if(strtoupper($ext) == "GIF") | |
{ | |
$image = imagecreatefromgif($imgpath); | |
} | |
else | |
{ | |
echo "COULD NOT CREATE IMAGE AT -> $imgpath"; | |
exit(); | |
} | |
if($image != NULL && $image != FALSE) | |
{ | |
$thiswidth = imagesx($image); | |
$thisheight = imagesy($image); | |
if($resample == true) | |
imagecopyresampled($spread, $image, $pointerw, $pointerh, 0, 0, $square, $square, $thiswidth, $thisheight); | |
else | |
imagecopyresized($spread, $image, $pointerw, $pointerh, 0, 0, $square, $square, $thiswidth, $thisheight); | |
$pointerw += $square; | |
if($pointerw >= $totalwidth) | |
{ | |
$pointerw = 0; | |
$pointerh += $square; | |
} | |
if(!imagedestroy($image)) //Destroy image to free resources. | |
{ | |
echo "Image destroy FAILED!"; | |
exit(); | |
} | |
} | |
else | |
{ | |
echo "FAIL -> ..\\beer_img\\$imgpath"; | |
exit(); | |
} | |
$count++; | |
if(($limit > 0 && $count > $limit) || ($until > 0 && $count > $until)) | |
break; | |
} | |
} | |
} while($count < $until && $until > 0); | |
//Flush out the image. | |
if($type == "jpg") | |
{ | |
header('Content-type: image/jpeg'); | |
imagejpeg($spread, NULL, $jpgquality); | |
} | |
else if($type == "png") | |
{ | |
header('Content-type: image/png'); | |
imagepng($spread, NULL, $pngquality); | |
} | |
imagedestroy($spread); //Destroy image to free resources. | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment