/** * Get the image data as a data URL for an artist & album * * @param string $artist * @param string $album * @param int $size * @return string */ public static function getImageData($artist, $album, $size) { // build the expected file name $image_file = Config::get('app.music-artwork-path') . md5($artist . $album) . "-{$size}.jpg"; // does the file exist? if (file_exists($image_file)) { // convert it to a string & return it return Image::toDataURL($image_file); } // couldn't find the artwork, return the default artwork switch ($size) { case 180: return Image::toDataURL(Config::get('app.music-artwork-path') . 'default-album-180.jpg'); case 320: return Image::toDataURL(Config::get('app.music-artwork-path') . 'default-album-320.jpg'); default: return Image::toDataURL(Config::get('app.music-artwork-path') . 'default-album.jpg'); } }
Database::execute("delete from songs;"); Database::execute("delete from playlists;"); Database::execute("delete from playlists_songs;"); Kint::dump("database emptied"); }); $klein->respond('GET', '/view-db', function ($request, $response) { $tables = Database::query("SELECT name FROM sqlite_master WHERE type='table';"); foreach ($tables as $t) { Kint::dump(Database::query("SELECT * FROM {$t['name']};")); } }); $klein->respond('GET', '/test-route', function ($request, $response) { $files = array('/home/dave/temp/default-album-180.png', '/home/dave/temp/default-album-320.png', '/home/dave/temp/default-album.png'); foreach ($files as $f) { Kint::dump($f); $dataurl = Image::toDataURL($f); Kint::dump($dataurl); if ($dataurl) { file_put_contents($f . '.txt', $dataurl); } } }); // Handle a 404 - route not found // $klein->respond('404', function ($request) { $r = "<h1>Uh-oh. 404!</h1>"; $r .= "<p>The path '" . $request->uri() . "' does not exist.</p>"; return $r; }); // Execute! //