| | 199 | // Generate video cover thumbnails (if necessary) |
| | 200 | if (!function_exists('imagecreate')) { |
| | 201 | custom_error("Please install the GD library for PHP.\n" |
| | 202 | .'The package is usually called something like php-gd.'); |
| | 203 | } |
| | 204 | function generate_thumbnail($videoid, $cover_filename, $cover_thumbnail_filename, $last_modified) { |
| | 205 | global $db, $Last_Modified; |
| | 206 | $filetype = trim(`file -bi "$cover_filename"`); |
| | 207 | switch ($filetype) { |
| | 208 | case 'image/jpeg': |
| | 209 | $im = imagecreatefromjpeg($cover_filename); |
| | 210 | break; |
| | 211 | case 'image/png': |
| | 212 | $im = imagecreatefrompng($cover_filename); |
| | 213 | break; |
| | 214 | case 'image/gif': |
| | 215 | $im = imagecreatefromgif($cover_filename); |
| | 216 | break; |
| | 217 | default: |
| | 218 | return false; |
| | 219 | } |
| | 220 | list($width, $height) = getimagesize($cover_filename); |
| | 221 | $thumb = imagecreatetruecolor(video_img_width, video_img_height); |
| | 222 | imagecopyresampled($thumb, $im, 0, 0, 0, 0, video_img_width, video_img_height, $width, $height); |
| | 223 | imagejpeg($thumb, $cover_thumbnail_filename, 100); |
| | 224 | if (isset($Last_Modified[$videoid]['modified'])) { |
| | 225 | $sh = $db->query('UPDATE mythweb_video_thumbs SET modified='.$last_modified.', width='.video_img_width.', height='.video_img_height.' WHERE videoid='.$videoid); |
| | 226 | $sh->finish(); |
| | 227 | } else { |
| | 228 | $sh = $db->query('INSERT INTO mythweb_video_thumbs (videoid, modified, width, height) VALUES (\''.$videoid.'\', \''.$last_modified.'\', '.video_img_width.', '.video_img_height.')'); |
| | 229 | $sh->finish(); |
| | 230 | } |
| | 231 | return true; |
| | 232 | } |
| | 233 | $Last_Modified = array(); |
| | 234 | $sh = $db->query('SELECT * FROM mythweb_video_thumbs'); |
| | 235 | while ($row = $sh->fetch_assoc()) { |
| | 236 | $Last_Modified[$row['videoid']] = array ('modified' => $row['modified'], 'dimensions' => array ('w' => $row['width'], 'h' => $row['height'])); |
| | 237 | } |
| | 238 | $sh->finish(); |
| | 239 | foreach ($All_Shows as $show) { |
| | 240 | $cover_filename = 'data/video_covers/'.basename($show->coverfile); |
| | 241 | $cover_thumbnail_filename = 'data/video_cover_thumbs/'.basename($show->coverfile); |
| | 242 | // Do we even need a thumbnail? |
| | 243 | if (file_exists($cover_filename)) { |
| | 244 | $Image_Last_Modified = filemtime($cover_filename); |
| | 245 | if (file_exists($cover_thumbnail_filename)) { |
| | 246 | // Update thumbnail |
| | 247 | if (isset($Last_Modified[$show->intid])) { |
| | 248 | if ($Last_Modified[$show->intid]['modified'] != $Image_Last_Modified) |
| | 249 | generate_thumbnail($show->intid, $cover_filename, $cover_thumbnail_filename, $Image_Last_Modified); |
| | 250 | else if ($Last_Modified[$show->intid]['dimensions']['w'] != video_img_width || $Last_Modified[$show->intid]['dimensions']['h'] != video_img_height) |
| | 251 | generate_thumbnail($show->intid, $cover_filename, $cover_thumbnail_filename, $Image_Last_Modified); |
| | 252 | } else |
| | 253 | generate_thumbnail($show->intid, $cover_filename, $cover_thumbnail_filename, $Image_Last_Modified); |
| | 254 | } else |
| | 255 | generate_thumbnail($show->intid, $cover_filename, $cover_thumbnail_filename, $Image_Last_Modified); |
| | 256 | } else { |
| | 257 | // Delete any old thumbnails |
| | 258 | $sh = $db->query('DELETE IGNORE FROM mythweb_video_thumbs WHERE videoid = '.$show->intid); |
| | 259 | $sh->finish(); |
| | 260 | if (file_exists($cover_thumbnail_filename)) |
| | 261 | unlink($cover_thumbnail_filename); |
| | 262 | } |
| | 263 | } |
| | 264 | |