jargon

NenGame PHP 0-046 Images Module by Nick of Neinstar Filmz

Oct 12th, 2016
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.05 KB | None | 0 0
  1. <?php
  2.  
  3. $nenini=false;
  4. echo render_images();
  5.  
  6. function create_thumb($src,$dest,$desired_width = false, $desired_height = false)
  7. {
  8.     /*If no dimenstion for thumbnail given, return false */
  9.     if (!$desired_height&&!$desired_width) return false;
  10.     $fparts = pathinfo($src);
  11.     $ext = strtolower($fparts['extension']);
  12.     /* if its not an image return false */
  13.     if (!in_array($ext,array('gif','jpg','png','jpeg'))) return false;
  14.    
  15.     /* read the source image */
  16.     if ($ext == 'gif')
  17.         $resource = imagecreatefromgif($src);
  18.     else if ($ext == 'png')
  19.         $resource = imagecreatefrompng($src);
  20.     else if ($ext == 'jpg' || $ext == 'jpeg')
  21.         $resource = imagecreatefromjpeg($src);
  22.    
  23.     $width  = imagesx($source_image);
  24.     $height = imagesy($source_image);
  25.     /* find the "desired height" or "desired width" of this thumbnail, relative to each other, if one of them is not given  */
  26.     if(!$desired_height)
  27.         $desired_height = floor($height*($desired_width/$width));
  28.     if(!$desired_width)
  29.         $desired_width  = floor($width*($desired_height/$height));
  30.     /* create a new, "virtual" image */
  31.     $virtual_image = imagecreatetruecolor($desired_width,$desired_height);
  32.    
  33.     if($width<$desired_width){
  34.         $desired_width=$width;
  35.         $desired_height=$height;
  36.     }
  37.     /* copy source image at a resized size */
  38.     imagecopyresized($virtual_image,$resource,0,0,0,0,$desired_width,$desired_height,$width,$height);
  39.    
  40.     /* create the physical thumbnail image to its destination */
  41.     /* Use correct function based on the desired image type from $dest thumbnail source */
  42.     $fparts = pathinfo($dest);
  43.     $ext = strtolower($fparts['extension']);
  44.     /* if dest is not an image type, default to jpg */
  45.     if (!in_array($ext,array('gif','jpg','png','jpeg'))) $ext = 'png';
  46.     $dest = $fparts['dirname'].'/'.$fparts['filename'].'.'.$ext;
  47.    
  48.     if ($ext == 'gif')
  49.         imagegif($virtual_image,$dest);
  50.     else if ($ext == 'png')
  51.         imagepng($virtual_image,$dest,1);
  52.     else if ($ext == 'jpg' || $ext == 'jpeg')
  53.         imagejpeg($virtual_image,$dest,100);
  54.    
  55.     return array(
  56.         'width'     => $width,
  57.         'height'    => $height,
  58.         'new_width' => $desired_width,
  59.         'new_height'=> $desired_height,
  60.         'dest'      => $dest
  61.     );
  62. }
  63.  
  64. function render_images()
  65. {
  66.     global $nenini;
  67.     $ret='';
  68.    
  69.     $nenini['image.wild']='*.png';
  70.     $nenini['title']='Image Archives';
  71.  
  72.     $ret.=
  73.         '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'.
  74.         '<html>'.
  75.         '<head>'.
  76.         '<title>'.
  77.         $nenini['title'].
  78.         '</title>'.
  79.         '</head>'.
  80.         '<style media="screen" type="text/css">'.
  81.         '@import "style.css";'.
  82.         '</style>'.
  83.         '<script language="JavaScript" src="index.js"></script>'.
  84.         '<script src="/Glow JS 0-01/Glow JS 0-00 Parallax.js" language="JavaScript"></script>'.
  85.         '<body link="grey" alink="grey" vlink="grey" onload="JsParallax_ini();">'.
  86.         '<table border="0px" cellpadding="8px" cellspacing="4px" width="100%">'.
  87.         '<tr>'.
  88.         '<td colspan="2">'.
  89.         '<p><font color="red" face="Courier New" size="22pt"><b>neinstar filmz</b></font></p>'.
  90.         '</td>'.
  91.         '</tr>'.
  92.         '<tr>'.
  93.         '<td colspan="2">'.
  94.         '<h1>'.$nenini['title'].'</h1>'.
  95.         '</td>'.
  96.         '</tr>'.
  97.         '<tr>'.
  98.         '<td>';
  99.        
  100.     $prefix='';
  101.     $suffix=$_SERVER['SCRIPT_NAME'];
  102.     while(strpos($suffix,'/')!==false){
  103.         $prefix.=substr($suffix,0,strpos($suffix,'/')+1);
  104.         $suffix=substr($suffix,strpos($suffix,'/')+1);
  105.         if(!is_dir($prefix))
  106.             mkdir($prefix);
  107.     }
  108.  
  109.     echo '<h1>'.$_SERVER['DOCUMENT_ROOT'].$prefix.$nenini['image.wild'].'</h1><br>';
  110.    
  111.     $dat=glob($_SERVER['DOCUMENT_ROOT'].$prefix.$nenini['image.wild']);
  112.     ksort($dat);
  113.  
  114.     $ret.='<table border="0px" cellspacing="8px" cellspacing="4px">';
  115.  
  116.     $ct=0;
  117.     $temp='';
  118.  
  119.     if(!is_dir($_SERVER['DOCUMENT_ROOT'].'/thumbs/'))
  120.         mkdir($_SERVER['DOCUMENT_ROOT'].'/thumbs/');
  121.    
  122.     foreach($dat as $fn){
  123.         echo '"'.$fn.'"<br>';
  124.         $ct++;
  125.         $ct=($ct % 5);
  126.         $src=$fn;
  127.        
  128.         $prefix='';
  129.         $suffix=$fn;
  130.         while(strpos($suffix,'/')!==false){
  131.             $prefix.=substr($suffix,0,strpos($suffix,'/')+1);
  132.             $suffix=substr($suffix,strpos($suffix,'/')+1);
  133.             if(!is_dir($prefix))
  134.                 mkdir($prefix);
  135.         }
  136.            
  137.         $dest=$_SERVER['DOCUMENT_ROOT'].'/thumbs'.substr($fn,strlen($_SERVER['DOCUMENT_ROOT']));
  138.        
  139.         $prefix='';
  140.         $suffix=$dest;
  141.         while(strpos($suffix,'/')!==false){
  142.             $prefix.=substr($suffix,0,strpos($suffix,'/')+1);
  143.             $suffix=substr($suffix,strpos($suffix,'/')+1);
  144.             echo '"'.$prefix.'"<br>';
  145.             if(!is_dir($prefix))
  146.                 mkdir($prefix);
  147.         }
  148.        
  149.         if(!is_file($dest)){
  150.             create_thumb($fn,$dest,240,false);
  151.             echo '<tt>create_thumb("'.$fn.'","'.$dest.'",240,false)</tt><br>';
  152.         }
  153.            
  154.         $temp.='<td bgcolor="black" align="center" valign="middle" class="picframe"><tt>img src="data:image/png;base64,'.base64_encode(file_get_contents($dest)).'" style="max-width: 240px;"</tt></td>';
  155.        
  156.         if($ct===0){
  157.             '<tr>'.$temp.'</tr>';
  158.             $temp='';
  159.         }
  160.     }
  161.  
  162.     if(strlen($temp)>0)
  163.         $ret.='<tr>'.$temp.'<td colspan="'.(5-$ct).'"></td></tr>';
  164.  
  165.     $ret.=
  166.         '</table>'.
  167.         '<p><table border="0px" cellpadding="8px" cellspacing="4px">'.
  168.         '<tr>'.
  169.         '<td><div class="stats">Series</div></td>'.
  170.         '<td><div class="stats"># Images</div></td>'.
  171.         '</tr>'.
  172.         '<tr>'.
  173.         '<td align="left"><a href="./Nick/"><font size="+2">Nick</b></font></a></td>'.
  174.         '<td align="right">4</td>'.
  175.         '</tr>'.
  176.         '<tr>'.
  177.         '<td align="left"><a href="./emblems/"><font size="+2"><b>Emblems</b></font></a></td>'.
  178.         '<td align="right">4</td>'.
  179.         '</tr>'.
  180.         '<tr>'.
  181.         '<td align="left"><a href="./shiprekt/"><font size="+2"><b>JailCon / #SHIPREKT Tour</b></font></a></td>'.
  182.         '<td align="right">165</td>'.
  183.         '</tr>'.
  184.         '<tr>'.
  185.         '<td align="left"><a href="./Death\'s Embrace/"><font size="+2"><b>Death\'s Embrace</b></font></a></td>'.
  186.         '<td align="right">4</td>'.
  187.         '</tr>'.
  188.         '<tr>'.
  189.         '<td align="left"><a href="./site/"><font size="+2"><b>Site</b></font></a></td>'.
  190.         '<td align="right">1</td>'.
  191.         '</tr>'.
  192.         '</table></p>'.
  193.         '</td>'.
  194.         '<td id="player"></td>'.
  195.         '</tr>'.
  196.         '<tr>'.
  197.         '<td colspan="2"><font size="+3">(<a href="../">Back</a>)</font></td>'.
  198.         '</tr>'.
  199.         '</table>'.
  200.         '</body>'.
  201.         '</html>';
  202.     return $ret;
  203. }
  204. ?>
Add Comment
Please, Sign In to add comment