Techno

NTH thumbnailer @ technoslab.blogspot.com

Apr 17th, 2011
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  
  5. NTH THUMBNAIL GENERATOR ( generate thumbnail of nth files using PHP )
  6.  
  7. POSTED AT TECHNOSLAB.BLOGSPOT.COM
  8.  
  9. Usage :
  10.  
  11. => Save this file as nth.php
  12.  
  13. => Call it in your html as <img src='nth.php?file=xyz.nth' />
  14.  
  15. */
  16.  
  17. require_once"tdesk/class.pclzip.php";
  18.  
  19. // Get it at www.phpconcept.net/pclzip.
  20.  
  21. if(!isset($_GET['file']) || !is_file($_GET['file']))exit('Feed me a nth file');
  22.  
  23. // Add more security checks like extension/filesize check.
  24.  
  25. $nth = new PclZip($_GET['file']);
  26.  
  27. // Create a new instance of Pclzip class.
  28.  
  29. $content = $nth->extract(PCLZIP_OPT_BY_NAME,'theme_descriptor.xml',PCLZIP_OPT_EXTRACT_AS_STRING);
  30.  
  31. // Extract theme_descriptor_xml file as string.
  32.  
  33. $xml = simplexml_load_string($content['0']['content']);
  34.  
  35. // Load the sting in a simple xml object.
  36.  
  37. $src = trim($xml->wallpaper['src']) or $src = trim($xml->wallpaper['main_display_graphics']);
  38.  
  39. // Get main theme background image's name.
  40.  
  41. $img = $nth->extract(PCLZIP_OPT_BY_NAME,$src,PCLZIP_OPT_EXTRACT_AS_STRING);
  42.  
  43. // Extract the main background image as string.
  44.  
  45. $img = $img['0']['content'];
  46.  
  47. // Obtain the string.
  48.  
  49. $img = imagecreatefromstring($img);
  50.  
  51. // Create an image from that string.
  52.  
  53. header('Content-type: image/jpeg');
  54.  
  55. // Send a header to the browser saying that the output is of image/jpeg type.
  56.  
  57. imagejpeg($img);
  58.  
  59. // Output the image to the browser.
  60.  
  61. imagedestroy($img);
  62.  
  63. // Clean and free up resources.
  64.  
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment