Share Pastebin
Guest
Public paste!

cute image.mdu

By: a guest | Mar 17th, 2010 | Syntax: PHP | Size: 41.26 KB | Hits: 199 | Expires: Never
Copy text to clipboard
  1. <?PHP
  2. ///////////////////////////////////////////////////////////////////
  3. //Original images.mdu modified by FI-DD
  4. //http://cutephp.com/forum/index.php?showuser=2775
  5. //http://english.cutenews.ru/forum/profile.php?mode=viewprofile&u=2
  6. ///////////////////////////////////////////////////////////////////
  7.  
  8. if($member_db[1] > 3 or ($member_db[1] != 1 and $action == "doimagedelete")){ msg("error", "Access Denied", "You don't have permission to manage images"); }
  9.  
  10. $allowed_extensions = array("gif", "jpg", "bmp", "png", "jpe", "jpeg");
  11.  
  12. /////////////////////////
  13. //Configuration of popups
  14. /////////////////////////
  15. $popup_in_news = false;
  16. $popup_in_manager = false;
  17. $images_per_page = 10;
  18. /////////////////////////
  19. //Configuration of missing thumbs
  20. //(If you have images without thumbs they will automatically be generated with the following parameters.)
  21. $missing_thumbs_size = 150;
  22. $missing_thumbs_format = "normal"; //Change to "square" for squared thumbs or to "normal" to keep the dimensions
  23. //////////////////////////////////
  24.  
  25. $static_path_image_upload = $config_path_image_upload;
  26.  
  27. $folder = $_GET['folder'];
  28. $config_path_image_upload = $config_path_image_upload.($folder == '' ? '' : '/'.$folder);
  29.  
  30. //Create /thumbs folder
  31. if(!file_exists($config_path_image_upload.'/thumbs')) @mkdir($config_path_image_upload.'/thumbs');
  32. chmod( $config_path_image_upload.'/'.$new_dir, 0777 );
  33.  
  34.  
  35. //Create .htaccess file
  36. create_htaccess($config_path_image_upload.'/thumbs/.htaccess');
  37.  
  38.  
  39. // ********************************************************************************
  40.  
  41. // Show Preview of Image
  42.  
  43. // ********************************************************************************
  44. if($action == "preview"){
  45.  
  46. echo <<<PREVIEWHTML
  47. <HTML>
  48.                 <HEAD>
  49.                                 <TITLE>Image Preview</TITLE>
  50.                                 <script language='javascript'>
  51.                                                 var NS = (navigator.appName=="Netscape")?true:false;
  52.  
  53.                                                 function fitPic() {
  54.                                                                 iWidth = (NS)?window.innerWidth:document.body.clientWidth;
  55.                                                                 iHeight = (NS)?window.innerHeight:document.body.clientHeight;
  56.                                                                 iWidth = document.images[0].width - iWidth;
  57.                                                                 iHeight = document.images[0].height - iHeight;
  58.                                                                 window.resizeBy(iWidth, iHeight-1);
  59.                                                                 self.focus();
  60.                                                 };
  61.                                 </script>
  62.                 </HEAD>
  63.                 <BODY bgcolor="#FFFFFF" onload='fitPic();' topmargin="0" marginheight="0" leftmargin="0" marginwidth="0">
  64.                                 <script language='javascript'>
  65.                                
  66.                                                 document.write( "<table border=0 style=&quot;height:100%; width:100%; text-align:center;&quot;><tr><td>" );
  67.                                                 document.write( "<img src='$path/$image' border=0>" );
  68.                                                 document.write( "</td></tr></table>" );
  69.  
  70.                                 </script>
  71.                 </BODY>
  72.  
  73. </HTML>
  74.  
  75. PREVIEWHTML;
  76. }
  77. // ********************************************************************************
  78.  
  79. // Show Images List
  80.  
  81. // ********************************************************************************
  82. elseif($action != "doimagedelete")
  83.  
  84. {
  85.  
  86.                 if($action == "quick")
  87.         {
  88.                         echo"<html>
  89.                                                 <head>
  90.                                                 <title>Insert Image</title>
  91.                                                 <style type=\"text/css\">
  92.                                                 <!--
  93.                                                 select, option, textarea, input {
  94.                                                  BORDER: #808080 1px solid;
  95.                                                  COLOR: #000000;
  96.                                                  FONT-SIZE: 11px;
  97.                                                  FONT-FAMILY: Verdana; BACKGROUND-COLOR: #ffffff
  98.                                                 }
  99.                                                 BODY, TD {text-decoration: none; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt;}
  100.                                                                         a:active,a:visited,a:link {font-size : 10px; color: #808080; font-family: verdana; text-decoration: none;}
  101.                                                                         a:hover {font-size : 10px; color: darkblue; font-weight:bold; text-decoration: none; }
  102.                                                                         .panel                            { border: 1px dotted silver; background-color: #F7F6F4;}
  103.                                                 -->
  104.                                                 </style>
  105.                                                 </head>
  106.                                                 <body bgcolor=#FFFFFF>
  107.                                                 <script language=\"javascript\" type=\"text/javascript\">
  108.                                                 <!--
  109.                                                
  110.                                                 function insertimage(selectedImage, path, link1, link2) {
  111.                                                  var area = '$area';
  112.                                                                 alternativeText = document.forms['properties'].alternativeText.value;
  113.                                                                 imageAlign = document.forms['properties'].imageAlign.value;
  114.                                                                 imageBorder = document.forms['properties'].imageBorder.value;
  115.                                                                 hSpace = document.forms['properties'].hSpace.value;
  116.                                                                 vSpace = document.forms['properties'].vSpace.value;
  117.  
  118.                                                                 finalImage = link1 +\"<img border=\\\"\"+ imageBorder +\"\\\" align=\\\"\"+ imageAlign +\"\\\" alt=\\\"\"+ alternativeText +\"\\\" hspace=\\\"\"+ hSpace +\"\\\" vspace=\\\"\"+ vSpace +\"\\\" src=\\\"".$config_http_script_dir.substr($config_path_image_upload, 1)."/\"+ path +\"\"+ selectedImage +\"\\\">\" + link2;
  119.                                                 ";
  120.  
  121.                                                 if($wysiwyg){
  122.                                           echo"
  123.                                           MYRTE=window.opener.document.getElementById(area).contentWindow;
  124.                                           window.opener.currentRTE=area;
  125.                                           MYRTE.document.body.innerHTML += link1 +\"<img border=\\\"\"+ imageBorder +\"\\\" align=\\\"\"+ imageAlign +\"\\\" alt=\\\"\"+ alternativeText +\"\\\" hspace=\\\"\"+ hSpace +\"\\\" vspace=\\\"\"+ vSpace +\"\\\" src=\\\"".$config_http_script_dir.substr($config_path_image_upload, 1)."/\"+ path +\"\"+ selectedImage +\"\\\">\" + link2;
  126.                                           ";
  127.                                                 }
  128.                                                 else{ echo"opener.document.getElementById(area).value += finalImage;"; }
  129.  
  130.                                                 echo"
  131.                                                                 window.close();
  132.                                                                 //opener.document.getElementById(area).focus();
  133.                                                 }
  134.                                                
  135.                                                 function PopupPic(sPicURL, path) {
  136.                                                         window.open('$PHP_SELF?mod=images&action=preview&image='+sPicURL+'&path='+path, '', 'resizable=1,HEIGHT=200,WIDTH=200');
  137.                                                 }
  138.                                                
  139.                                                 function changealt(img_name) {
  140.                                                 document.forms['properties'].alternativeText.value = img_name;
  141.                                                 }
  142.                                                                 window.resizeTo(850, 600);
  143.                                                                 self.focus();
  144.                                                 //-->
  145.                                                 </script>";
  146.  
  147.         }else{ echoheader("images","Manage Images"); }
  148.  
  149. // ********************************************************************************
  150.  
  151. // Upload Image(s)
  152.  
  153. // ********************************************************************************
  154. //Rename image
  155. if ($action == 'rename' and $image and $name){
  156.         $dir = end(explode("/", $path));
  157.         @rename($path.'/'.$image, $path.'/'.$name);
  158.         @rename($path.'/thumbs/'.$image, $path.'/thumbs/'.$name);
  159.         echo '<script type="text/javascript">self.location.href="'.$PHP_SELF.'?mod=images&folder='.($path == $static_path_image_upload ? '' : $dir).'&start_from='.$start_from.'";</script>';
  160. }
  161.  
  162. //Rename subfolder
  163. if ($action == 'change_dir' and $new_name){
  164.         $new_name = str_replace(" ", "_", $new_name);
  165.         $path_arr = explode("/", $config_path_image_upload);
  166.         $length = strlen(end($path_arr))+1;
  167.         $new_path = substr($config_path_image_upload, 0, -$length);
  168.         if(file_exists($new_path.'/'.$new_name)) echo "<font color=red>Error, ".$new_name." already exists.</font>";
  169.         else{
  170.         @rename($config_path_image_upload, $new_path.'/'.$new_name);
  171.         echo '<script type="text/javascript">self.location.href="'.$PHP_SELF.'?mod=images&folder='.$new_name.'";</script>';
  172.         }
  173.        
  174. }
  175.  
  176. //Create subfolder
  177. if ($action == 'create_dir' and $new_dir){
  178.         $new_dir = str_replace(" ", "_", $new_dir);
  179.         if(file_exists($config_path_image_upload.'/'.$new_dir)) echo "<font color=red>Error, ".$new_dir." already exists.</font>";
  180.         else{
  181.                 @mkdir($config_path_image_upload.'/'.$new_dir, 0777);
  182.                 chmod( $config_path_image_upload.'/'.$new_dir, 0777 );
  183.                 echo '<script type="text/javascript">self.location.href="'.$PHP_SELF.'?mod=images&folder='.$new_dir.'";</script>';
  184.                         create_htaccess($config_path_image_upload.'/'.$new_dir.'/.htaccess');
  185.         }
  186. }
  187.  
  188. //Delete empty subfolder
  189. if ($action == "delete_dir"){
  190.         unlink($config_path_image_upload.'/thumbs/.htaccess');
  191.         rmdir($config_path_image_upload.'/thumbs');
  192.         unlink($config_path_image_upload.'/.htaccess');
  193.         rmdir($config_path_image_upload);
  194.         echo '<script type="text/javascript">self.location.href="'.$PHP_SELF.'?mod=images";</script>';
  195. }
  196.  
  197. //Move file
  198. if ($action == "move_file"){
  199.         if(!file_exists($config_path_image_upload.'/'.$file)){
  200.                 copy($old_path.'/'.$file, $config_path_image_upload.'/'.$file);
  201.                 copy($old_path.'/thumbs/'.$file, $config_path_image_upload.'/thumbs/'.$file);
  202.                 unlink($old_path.'/'.$file);
  203.                 unlink($old_path.'/thumbs/'.$file);
  204.                 //echo '<script type="text/javascript">self.location.href="'.$PHP_SELF.'?mod=images&folder='.$folder.'";</script>';
  205.         }
  206. }
  207.  
  208. //Upload image
  209. if($subaction == "upload")
  210. {
  211.  
  212. for ($i = 0; $i < count($_FILES['image']['name'])-1; $i++) {
  213.        
  214.         $image = $_FILES['image']['tmp_name'][$i];
  215.         $image_name = $_FILES['image']['name'][$i];
  216.         $image_name = str_replace(" ", "_", $image_name);
  217.         $img_name_arr = explode(".",$image_name);
  218.         $type = end($img_name_arr);
  219.  
  220.         if($image_name == ""){ $img_result .= "<br><font color=red>$current_image -> No File Specified For Upload!</font>"; }
  221.         elseif( !isset($overwrite) and file_exists($config_path_image_upload."/".$image_name)){ $img_result .= "<br><font color=red>$image_name -> Image already exist!</font>";}
  222.         elseif( !(in_array($type, $allowed_extensions) or in_array(strtolower($type), $allowed_extensions)) ){
  223.                            $img_result .= "<br><font color=red>$image_name ->This type of file is not allowed !!!</font>";
  224.         }
  225. else
  226.  
  227. {
  228.  
  229. @copy($image, $config_path_image_upload.'/'.$image_name, 0777) or $img_result = "<font color=red>Not able to upload image.</font><br />Make sure that file upload is enabled or contact your server administrator.";
  230.  
  231.  
  232. //Add watermark (text)
  233.         if ($watermark and $watermark_text != "") {
  234.                 if($watermark_font == "none") {
  235.                         @add_watermark($config_path_image_upload.'/'.$image_name, $watermark_text, $hotspot1, ($textcolor ? $textcolor : 'FFFFFF'), ($textsize ? $textsize : '12'));
  236.                 }
  237.                 else {
  238.                         @add_watermark($config_path_image_upload.'/'.$image_name, $watermark_text, $hotspot1, ($textcolor ? $textcolor : 'FFFFFF'), ($textsize ? $textsize : '12'), 'data/watermark/'.$watermark_font);
  239.                 }
  240.         }
  241.        
  242. //Add watermark (image)
  243.         if ($merge) {
  244.                 @mergePix($config_path_image_upload.'/'.$image_name, 'data/watermark/'.$watermark_image, $config_path_image_upload.'/'.$image_name, $hotspot2, ($merge_transition ? $merge_transition : '40'));
  245.         }
  246.        
  247. //Make thumb
  248. if ($max < 1 or $max == "") {$max = 100;}
  249.         if ($square == "yes") {
  250.         make_thumb($config_path_image_upload."/".$image_name, $config_path_image_upload."/thumbs/".$image_name, $max, 'square');
  251.         }
  252.         else make_thumb($config_path_image_upload."/".$image_name, $config_path_image_upload."/thumbs/".$image_name, $max, 'normal');
  253.        
  254. //Rounded corners
  255.         if($corners){
  256.                 if($corners_thumb){
  257.                         roundedCorners($config_path_image_upload.'/thumbs/'.$image_name, $corners_thumb_radius, $corners_thumb_background);
  258.                 }
  259.                 if($corners_image){
  260.                         roundedCorners($config_path_image_upload.'/'.$image_name, $corners_image_radius, $corners_image_background);
  261.                 }
  262.                
  263.         }
  264.  
  265. //Shadow
  266. if ($shadow == "yes") {
  267.         shadow($config_path_image_upload."/".$image_name);
  268.         shadow($config_path_image_upload."/thumbs/".$image_name);
  269. }
  270.  
  271. if(file_exists($config_path_image_upload."/".$image_name))
  272.  
  273. {
  274.                                          $img_result .= "<br><font color=green>$image_name -> Image was uploaded</font>";
  275.                                         }//if file is uploaded succesfully
  276.          }
  277. }
  278.  
  279. }
  280. //////////////
  281. //Upload Form
  282. //////////////
  283. ?>
  284. <form name="form" id="form" action="<?=$PHP_SELF; ?>?mod=images&folder=<?=$folder; ?>" method="post" enctype="multipart/form-data">
  285.  
  286. <table border="0" cellpading="0" cellspacing="0" width="100%">
  287.         <td height="33">
  288.         <b>Upload Image</b>
  289. <table border="0" cellpading="0" cellspacing="0" class="panel" cellpadding="8">
  290.         <tr>
  291.         <td height="25">
  292.  
  293. <table border="0" cellspacing="0" cellpadding="0" id="tblSample">
  294.  <tr id="row">
  295.   <td width="1" colspan="2">
  296.  
  297.   <script language="javascript">
  298. f = 0
  299. function file_uploader(which){
  300. if (which < f) return
  301.         f ++
  302.         d = document.getElementById('images_'+f)
  303.         d.innerHTML = '<input type="file" name="image['+f+']" id="images_'+f+'" value="" onchange="file_uploader('+f+');" /><br /><span id="images_'+(f+1)+'">'
  304. }
  305. document.writeln('<input type="file" name="image[0]" value="" onchange="file_uploader(0);" /><br />')
  306. document.writeln('<span id="images_1"></span>')
  307.  
  308. function showpreview(image,name){
  309.         if (image != ""){
  310.                 document.images[name].src = image;
  311.         } else {
  312.                 document.images[name].src = "skins/images/blank.gif";
  313.         }
  314. }
  315. </script>
  316.  
  317.   </td>
  318.   </tr>
  319. </table>
  320. <table border="0" cellspacing="0" cellpadding="0" style="margin-top:5px;">
  321.  <tr>
  322.   <td>
  323.   <input type="text" name="max" value="150" size="4"> Width of the thumb
  324.   </td>
  325.   </tr>
  326.  <tr>
  327.  <td>
  328.  <input style="border:0px; background-color:#F7F6F4;" type="checkbox" name="square" id="square" value="yes"><label title="Crop the thumb (width = height)" for="square">Crop the thumb</label>
  329.  </td></tr>
  330.  <tr>
  331.  <td><input style="border:0px; background-color:#F7F6F4;" type="checkbox" name="shadow" id="shadow" value="yes"><label title="Add a shadow to the thumb" for="shadow">Add a shadow</label>
  332.   </td>
  333.  </tr>
  334.  
  335.  <tr>
  336.  <td>
  337.  
  338.  <?
  339.  //Check for watermark fonts and images
  340.    $dir = opendir("data/watermark");
  341. while ($single_file = readdir($dir)){
  342.         $file_ending = strtolower(end(explode('.', $single_file)));
  343.         if ($file_ending == "jpg" or $file_ending == "jpeg" or $file_ending == "gif" or $file_ending == "png"){
  344.                 $watermarks[] = $single_file;
  345.         }
  346.         if ($file_ending == "ttf"){
  347.                 $fonts[] = $single_file;
  348.         }
  349. }
  350. ?>
  351.  
  352.  <label for="watermark"><input style="border:0px; background-color:#F7F6F4;" type="checkbox" name="watermark" id="watermark" onclick="javascript:ShowOrHide('make_watermark')"<?=(!extension_loaded('gd') ? ' disabled' : ''); ?>>Create watermark (text)</label><br />
  353.    <span id="make_watermark" style="display: none;">
  354.    <table width="200" align="center">
  355.    <tr>
  356.    <td>Text</td><td>Color</td><td>Size</td>
  357.    </tr>
  358.    <tr>
  359.    <td><input type="text" name="watermark_text" size="10" value="[date]"></td>
  360.    <td><input type="text" name="textcolor" maxlength="6" size="3" value="FFFFFF"></td>
  361.    <td><input type="text" name="textsize" maxlength="2" size="1" value="12"></td>
  362.    </tr>
  363.    <tr><td> </td></tr>
  364.    <tr>
  365.    <td>Position</td><td>Font</td>
  366.    </tr>
  367.    <tr>
  368.    <td><input type="radio" name="hotspot1" value="1"> <input type="radio" name="hotspot1" value="2"> <input type="radio" name="hotspot1" value="3"><br />
  369.    <input type="radio" name="hotspot1" value="4"> <input type="radio" name="hotspot1" value="5" checked> <input type="radio" name="hotspot1" value="6"><br />
  370.    <input type="radio" name="hotspot1" value="7"> <input type="radio" name="hotspot1" value="8"> <input type="radio" name="hotspot1" value="9"></td>
  371.    <td valign="top">
  372.    <? if($fonts) { ?>
  373.    <select name="watermark_font">
  374.    <option value="none">Select</option>
  375.    <? foreach($fonts as $font) {
  376.    echo '<option value="'.$font.'">'.$font.'</option>';
  377.    }
  378.    ?>
  379.    </select>
  380.    <? } else {echo "No fonts installed";} ?>
  381.         </td>
  382.    </tr>
  383.    </table></td></tr>
  384.    <br /></span>
  385.    
  386.    <tr><td>
  387.    <label for="merge"><input style="border:0px; background-color:#F7F6F4;" type="checkbox" name="merge" id="merge" onclick="javascript:ShowOrHide('make_merge')"<?=(!extension_loaded('gd') ? ' disabled' : ''); ?>>Create watermark (image)</label><br />
  388.    <span id="make_merge" style="display: none;">
  389.    <table width="200" align="center">
  390.    <tr>
  391.    <td>Transition</td>
  392.    </tr>
  393.    <tr>
  394.    <td><input type="text" name="merge_transition" maxlength="2" size="1" value="40"></td><td>(1 = invisible,<br /> 99 = full)</td>
  395.    </tr>
  396.    <tr><td> </td></tr>
  397.    <tr>
  398.    <td>Position</td><td>Watermark</td>
  399.    </tr>
  400.    <tr>
  401.    <td width="50%"><input type="radio" name="hotspot2" value="1"> <input type="radio" name="hotspot2" value="5"> <input type="radio" name="hotspot2" value="2"><br />
  402.    <input type="radio" name="hotspot2" value="8"> <input type="radio" name="hotspot2" value="0" checked> <input type="radio" name="hotspot2" value="6"><br />
  403.    <input type="radio" name="hotspot2" value="4"> <input type="radio" name="hotspot2" value="7"> <input type="radio" name="hotspot2" value="3"></td>
  404.    <td width="50%" valign="top">
  405.    <? if($watermarks) { ?>
  406.    <select onchange="showpreview('data/watermark/'+this.options[this.selectedIndex].value, 'previewimage')" name="watermark_image">
  407.    <? foreach($watermarks as $watermark_image) {
  408.    echo '<option value="'.$watermark_image.'">'.$watermark_image.'</option>';
  409.    }
  410.    ?>
  411.    </select><br />
  412.    <img name="previewimage" width="100px" src="data/watermark/<?=$watermarks[0]; ?>" align="left" style="margin: 5px;">
  413.    <? }
  414.    else { echo "No watermark images"; }
  415.    ?>
  416.    
  417.         </td>
  418.    </tr>
  419.    </table>
  420.    <br /></span>
  421.    </td></tr>
  422.    
  423.       <tr><td>
  424.    <label for="corners"><input style="border:0px; background-color:#F7F6F4;" type="checkbox" name="corners" id="corners" onclick="javascript:ShowOrHide('make_corners')"<?=(!extension_loaded('gd') ? ' disabled' : ''); ?>>Create rounded corners</label><br />
  425.    <span id="make_corners" style="display: none;">
  426.    <table width="250" align="right">
  427.    <tr><td><input type="checkbox" name="corners_image" checked="checked" />Image</td><td>
  428.    <input type="text" name="corners_image_radius" size="5" value="25" /> Radius<br />
  429.    <input type="text" name="corners_image_background" size="5" value="ffffff" /> Background</td></tr>
  430.    <tr><td><input type="checkbox" name="corners_thumb" checked="checked" />Thumbnail</td><td>
  431.    <input type="text" name="corners_thumb_radius" size="5" value="15" /> Radius<br />
  432.    <input type="text" name="corners_thumb_background" size="5" value="ffffff" /> Background</td></tr>
  433.    </table>
  434.    <br /></span>
  435.    </td></tr>
  436.  
  437.  <tr>
  438.   <td>
  439.   <INPUT TYPE="SUBMIT" name="submit" VALUE="Upload" style="font-weight:bold;"> &nbsp;
  440.   <input style="border:0px; background-color:#F7F6F4;" type=checkbox name=overwrite id=overwrite value=1><label title='Overwrite file(s) if exist' for=overwrite> Overwrite</label>
  441.  
  442. </td>
  443.  </tr>
  444. </table>
  445. <?=$img_result; ?>
  446. </table>
  447.  
  448.          <input type=hidden name=wysiwyg value='<?=$wysiwyg; ?>'>
  449.          <input type=hidden name=subaction value=upload>
  450.          <input type=hidden name=area value='<?=$area; ?>'>
  451.         <input type=hidden name=action value='<?=$action; ?>'>
  452.  </form>
  453.  
  454. <?
  455.  
  456. //////////////////
  457. //Image properties
  458. //////////////////
  459. if($action == "quick"){
  460. echo"
  461. <form name=\"properties\">
  462. <table style='margin-top:10px;' border=0 cellpading=0 cellspacing=0      width=100%>
  463.  
  464.          <td height=33>
  465.          <b>Image Properties</b>
  466. <table border=0 cellpading=0 cellspacing=0 class=\"panel\" style='padding:5px'width=290px; >
  467.  
  468.  
  469.           <tr>
  470.            <td width=80>Alt. Text: </td>
  471.            <td><input tabindex=1 type=text name=\"alternativeText\" style=\"width:150;\"></td>
  472.           </tr>
  473.  
  474.           <tr>
  475.            <td>Image Align</td>
  476.            <td>
  477.                 <select name='imageAlign' style='width:150'>
  478.                   <option value=none>None</option>
  479.                   <option value=left>Left</option>
  480.                   <option value=right>Right</option>
  481.                 </select>
  482.            </td>
  483.           </tr>
  484.  
  485.           <tr>
  486.            <td>Border</td>
  487.            <td><input type=text value='0' name=imageBorder style=\"width:35\"> pixels</td>
  488.           </tr>
  489.           <tr>
  490.            <td>hspace</td>
  491.            <td><input type=text value='15' name=hSpace style=\"width:35\"> pixels</td>
  492.           </tr>
  493.           <tr>
  494.            <td>vspace</td>
  495.            <td><input type=text value='5' name=vSpace style=\"width:35\"> pixels</td>
  496.           </tr>
  497.  
  498.          </table>
  499. </table></form>";
  500. }
  501.  
  502. ////////////////////////
  503. //Prepare image showing
  504. ////////////////////////
  505. echo"<tr><td><img height=1 style=\"height: 13px !important; height: 1px;\" border=0 src=\"skins/images/blank.gif\" width=1></td></tr>";
  506.  
  507. //Show folder dropdown
  508. echo "<tr><td><br />
  509. <form action='' method='post'>
  510. <select onchange=\"window.location=this.options[this.selectedIndex].value\">
  511. <option value=$PHP_SELF?mod=images&action=".$_GET['action']."&area=".$_GET['area']."&wysiwyg=".$_GET['wysiwyg']."&folder=".($_GET['folder'] == '' ? ' selected' : '').">Main</option>";
  512. echo get_subfolder($static_path_image_upload);
  513. echo"</select></form>";
  514.  
  515. //Show folder changing
  516. if($action != "quick" and $_GET['folder'] != ""){
  517.         echo '<form action="" method="post">';
  518.         echo '<input type="textbox" name="new_name" value="'.$_GET['folder'].'">';
  519.         echo '<input type="hidden" name="action" value="change_dir">';
  520.         echo ' <input type="submit" value="Change name">';
  521.         echo "</form></td></tr>";
  522. }
  523.  
  524. //Show folder creation
  525. if($action != "quick" and $_GET['folder'] == ""){
  526.         echo '<form action="" method="post">';
  527.         echo '<input type="textbox" name="new_dir" value="">';
  528.         echo '<input type="hidden" name="action" value="create_dir">';
  529.         echo ' <input type="submit" value="New dir">';
  530.         echo "</form></td></tr>";
  531. }
  532.  
  533. //Show delete button
  534. if(dir_is_empty($config_path_image_upload) and $_GET['folder'] != ""){
  535.         echo '<tr><td><form action="" method="post">';
  536.         echo '<input type="hidden" name="action" value="delete_dir">';
  537.         echo ' <input type="submit" value="Delete dir">';
  538.         echo "</form></td></tr>";
  539. }
  540.  
  541. echo"".((dir_is_empty($config_path_image_upload) and $_GET['folder'] != "") ? '' : '<tr><td><b><br />Uploaded Images</b></td></tr>')."<tr>
  542.  
  543.                 <td height=1>
  544. <FORM action='$PHP_SELF?mod=images&folder=$folder' METHOD='POST'>
  545.  <table width=100% height=100% cellspacing=0 cellpadding=0>";
  546.                
  547.                 $img_dir = opendir($config_path_image_upload);
  548.  
  549.                 $i = 0;
  550.  
  551.         while ($file = readdir($img_dir))
  552.         {
  553.        
  554.                 $img_name_arr = explode(".",$file);
  555.                 $img_type                  = end($img_name_arr);
  556.                 $img_name = substr($file, 0, -(strlen($img_type)+1));
  557.                
  558.                 if ((in_array($img_type, $allowed_extensions) or in_array(strtolower($img_type), $allowed_extensions)) and $file != ".." and $file != "." and $file != ".htaccess" and $file != "index.html" and is_file($config_path_image_upload."/".$file))
  559.                
  560.                  //Yes we'll store them in array for sorting
  561.                  $images_in_dir[] = $file;
  562.         }
  563.        
  564.         if($images_in_dir){
  565.        
  566.         natcasesort($images_in_dir);
  567.         reset($images_in_dir);
  568.        
  569.                 //Pagination
  570.         $images_per_page = ($images_per_page ? $images_per_page : 21);
  571.         $start_from = ($start_from ? $start_from : '');
  572.         $i = $start_from;
  573.         $j = 0;
  574.         //End Pagination
  575.        
  576.         foreach ($images_in_dir as $file) {
  577.        
  578.         //Add missing thumbs
  579.         if(!file_exists($config_path_image_upload.'/thumbs/'.$file))
  580.         make_thumb($config_path_image_upload.'/'.$file, $config_path_image_upload.'/thumbs/'.$file, $missing_thumbs_size, $missing_thumbs_format);
  581.         //Add missing thumbs
  582.        
  583.                
  584.                        
  585.                 //Pagination
  586.                 if ($j < $start_from){
  587.                         $j++;
  588.                         continue;
  589.                 }
  590.                 //End Pagination
  591.  
  592.                         $i++;
  593.  
  594.                         $this_size =  filesize($config_path_image_upload."/".$file);
  595.  
  596.                                 $total_size += $this_size;
  597.  
  598.                         $img_info = getimagesize($config_path_image_upload."/".$file);
  599.                         $img_info_thumb = getimagesize($config_path_image_upload."/thumbs/".$file);
  600.  
  601.                         if( $i%2 != 0 ){ $bg = "bgcolor=#F7F6F4"; }
  602.  
  603.                                         else{ $bg = ""; }
  604.  
  605. /////////////////////////////////
  606. //List images in addnews/editnews
  607. /////////////////////////////////
  608.                         if($action == "quick")
  609.  
  610.                         {
  611.                                 $my_area = str_replace("_", " ", $area);
  612.                                 $path_big = "";
  613.                                 $path_thumb = "thumbs/";
  614.                                
  615.                                 //If popup_in_news
  616.                                 if ($popup_in_news == true) {
  617.                                 $link1 = htmlspecialchars('<a href="javascript:popupMedia(&#039;'.$config_http_script_dir.'/data/upimages/'.($folder == '' ? '' : $folder.'/').$file.'&#039;, &#039;'.$img_info[0].'&#039;, &#039;'.$img_info[1].'&#039;)">');
  618.                                 }
  619.                                 //Else
  620.                                 else {
  621.                                 $link1 = htmlspecialchars('<a target="_blank" href="'.$config_http_script_dir.'/data/upimages/'.($folder == '' ? '' : $folder.'/').$file.'">');
  622.                                 }
  623.                                
  624.                                 $link2 = '</a>';
  625.                                 $empty_link = "";
  626.                                
  627.                                 //If popup_in_manager
  628.                                 if($popup_in_manager == true) {
  629.                                 echo"
  630.                                 <tr $bg><td height=16 width=10% align=center><a title='Preview this thumb in a popup' href=\"javascript:PopupPic(&#039;".$file."&#039;, &#039;".$config_path_image_upload."/thumbs&#039;)\"><img height='50px' style='border:0px;' src=".$config_http_script_dir.'/data/upimages/'.($folder == '' ? '' : $folder.'/').$file."></a>
  631.                                
  632.                                 <td height=16 width=15%>&nbsp;&nbsp;<a title='Preview this image in a popup' href=\"javascript:PopupPic(&#039;".$file."&#039;, &#039;".$config_path_image_upload."&#039;)\">$file</a>";
  633.                                 }
  634.                                 //Else
  635.                                 else {
  636.                                 echo"
  637.                                 <tr $bg><td height=16 width=10% align=center><a target=\"_blank\" title='Preview this thumb in a new page' href=\"".$config_path_image_upload."/thumbs/".$file."\"><img height='50px' style='border:0px;' src=".$config_path_image_upload."/thumbs/".$file."></a>
  638.                                 <td height=16 width=20%>&nbsp;&nbsp;<a target=\"_blank\" title='Preview this image in a new page' href=\"".$config_path_image_upload."/".$file."\">$file</a>";
  639.                                 }
  640.                                
  641.                                 echo"
  642.                                 <td height=16 width=15%>
  643.                                 <input type=\"button\" value=\"Insert Image\" onMouseOver=\"javascript:changealt('$file')\" onClick=\"javascript:insertimage('$file', '$path_big', '$empty_link', '$empty_link')\">&nbsp;
  644.                                 <td height=16 width=15%>
  645.                                 <input type=\"button\" value=\"Insert Thumb\" onMouseOver=\"javascript:changealt('$file')\" onClick=\"javascript:insertimage('$file', '$path_thumb', '$empty_link', '$empty_link')\">&nbsp;
  646.                                 <td height=16 width=15%>
  647.                                 <input type=\"button\" value=\"Clickable Thumb\" onMouseOver=\"javascript:changealt('$file')\" onClick=\"javascript:insertimage('$file', '$path_thumb', '$link1', '$link2')\">&nbsp;";
  648.                        
  649.                         echo "
  650.                                 <td height=16 align=right>
  651.  
  652.                                                         $img_info[0]x$img_info[1]&nbsp;&nbsp;
  653.  
  654.                                                         <td height=16 align=right>
  655.  
  656.                                                 &nbsp;". formatsize($this_size) ."
  657.  
  658.                                                         </tr>";
  659.  
  660.                         }
  661. ///////////////////////////////
  662. //List images in image manager
  663. ///////////////////////////////
  664.                         else
  665.                         {
  666.                                         echo"<tr $bg><td height=16>
  667.                                                         &nbsp;
  668.                                                         <td height=16 width=13% >
  669.                                                         <a target=\"_blank\" title='Preview this thumb' href=\"".$config_path_image_upload."/thumbs/".$file."\"><img height='50px' style='border:0px;' src=".$config_path_image_upload."/thumbs/".$file."></a>
  670.  
  671.                                                         <td height=16 width=40% >
  672.                                                         <a target=\"_blank\" title='Preview this image' href=\"".$config_path_image_upload."/".$file."\">$file</a>
  673.                                                        
  674.                                                         <td width=13%>Move to<br />
  675. <form action='' method='post'>
  676. <select onchange=\"window.location=this.options[this.selectedIndex].value\">
  677. <option value=$PHP_SELF?mod=images&action=move_file&area=".$_GET['area']."&wysiwyg=".$_GET['wysiwyg']."&folder=".($_GET['folder'] == '' ? ' selected' : '')."&old_path=".$config_path_image_upload."&file=".$file.">Main</option>";
  678. echo get_subfolder($static_path_image_upload, $config_path_image_upload, $move = true, $file);
  679. echo"</select>
  680.                                                        
  681.                                                        
  682.                                                         <td height=16 width=10% >
  683.                                                         <a title=\"Rename this image\" href=\"?mod=images&amp;action=rename&amp;path=$config_path_image_upload&amp;image=$file&amp;start_from=".$_GET['start_from']."\" onclick=\"if (ren=window.prompt('', '$file')){window.location.href=this.href+'&name='+ren;}return false;\">[rename]</a>
  684.  
  685.                                 <td height=16 align=right>
  686.                                                         $img_info[0]x$img_info[1]
  687.                                                         <td height=16 align=right>
  688.                                                 &nbsp;". formatsize($this_size) ."
  689.                                                 <td width=70 height=16 align=right>
  690.                                 <input type=checkbox name=images[$file] value=\"$file\">
  691.                                                         </tr>";
  692.                         }
  693.                                        
  694.                 //Pagination
  695.                 if ($i >= $images_per_page + $start_from){
  696.                         break;
  697.                 }
  698.                 //End Pagination
  699.                
  700.                 }//End foreach
  701.         }//End if($images_in_dir)
  702.                
  703.                
  704.                
  705.                 //Pagination
  706.                 if ($start_from > 0){
  707.                         $previous = $start_from - $images_per_page;
  708.                         $npp_nav .= '<a href="'.$PHP_SELF.'?mod=images&amp;start_from='.$previous.($action == "quick" ? '&amp;action=quick&amp;area='.$_GET['area'].'&amp;wysiwyg='.$_GET['wysiwyg'].'': '').'&folder='.$_GET['folder'].'">&lt;&lt;</a>';
  709.                 }
  710.  
  711.                 if (count($images_in_dir) > $images_per_page){
  712.                         $npp_nav .= ' [ ';
  713.                         $enpages_count = @ceil(count($images_in_dir) / $images_per_page);
  714.                         $enpages_start_from = 0;
  715.                         $enpages = '';
  716.  
  717.                         for ($j = 1; $j <= $enpages_count; $j++){
  718.                                 if ($enpages_start_from != $start_from){
  719.                                         $enpages .= '<a href="'.$PHP_SELF.'?mod=images&amp;start_from='.$enpages_start_from.($action == "quick" ? '&amp;action=quick&amp;area='.$_GET['area'].'&amp;wysiwyg='.$_GET['wysiwyg'].'': '').'&folder='.$_GET['folder'].'">'.$j.'</a> ';
  720.                         }        else {
  721.                                         $enpages .= ' <b> <u>'.$j.'</u> </b> ';
  722.                                 }
  723.  
  724.                                 $enpages_start_from += $images_per_page;
  725.                         }
  726.  
  727.                         $npp_nav .= $enpages;
  728.                         $npp_nav .= ' ] ';
  729.                 }
  730.  
  731.                 if (count($images_in_dir) > $i){
  732.                         $npp_nav .= '<a href="'.$PHP_SELF.'?mod=images&amp;start_from='.$i.($action == "quick" ? '&amp;action=quick&amp;area='.$_GET['area'].'&amp;wysiwyg='.$_GET['wysiwyg'].'': '').'&folder='.$_GET['folder'].'">&gt;&gt;</a>';
  733.                 }
  734.                 //End pagination
  735.                
  736.         if($i > 0){
  737.                         echo"<tr ><td colspan=\"3\" height=16>$npp_nav";
  738.                                 if($action != "quick"){
  739.                                                    echo" <td colspan=4 align=right>
  740.                                    <br><input type=submit value='Delete Selected Images'>
  741.                                                         </tr>";
  742.                                 }
  743.                         echo"<tr height=1>
  744.                                 <td      width=14>
  745.                                 &nbsp;
  746.                                 <td>&nbsp;
  747.                                 <td >
  748.                                 <br /><b>Total size</b>
  749.                         <td>&nbsp;<td>&nbsp;<td>&nbsp;
  750.                         <td align=right>
  751.  
  752.                                 <br /><b>". formatsize($total_size) .'</b>
  753.  
  754.                                 </tr>';
  755.  
  756.                 }
  757.  
  758.         echo'
  759.   </table><input type=hidden name=action value=doimagedelete></form></table>';
  760.  
  761.         if($action != "quick"){ echofooter(); }
  762.  
  763. }
  764.  
  765. // ********************************************************************************
  766.  
  767. // Delete Image
  768.  
  769. // ********************************************************************************
  770.  
  771. elseif($action == "doimagedelete")
  772.  
  773. {
  774. if(!isset($images)){             msg("info","No Images selected","You must select images to be deleted.", "$PHP_SELF?mod=images"); }
  775.                 foreach($images as $image){
  776.                                 unlink($config_path_image_upload."/".$image) or print("Could not delete image <b>$file</b>");
  777.                                 unlink($config_path_image_upload."/thumbs/".$image) or print("Could not delete thumb <b>$file</b>");
  778.                 }
  779.                 msg("info","Image(s) Deleted","The image was successfully deleted.", "$PHP_SELF?mod=images");
  780.  
  781. }
  782.  
  783. /////////////
  784. //Functions//
  785. /////////////
  786.  
  787. ///////////////////////////
  788. //Function: get_subfolder
  789. //Creates a dropdown for all subfolders
  790. ///////////////////////////
  791. function get_subfolder($path, $old_path = false, $move = false, $image = false){
  792.  
  793. $dir = opendir($path);
  794.         while ($subfolder = readdir($dir)) {
  795.                 if(is_dir($path.'/'.$subfolder) and $subfolder != "." and $subfolder != ".." and $subfolder != "thumbs"){
  796.                         $all_subfolders .= "<option value=".$PHP_SELF."?mod=images&action=".($move ? 'move_file' : $_GET['action'])."&area=".$_GET['area']."&wysiwyg=".$_GET['wysiwyg']."&folder=$subfolder".($move ? '&old_path='.$old_path.'&file='.$image : '')." ".($_GET['folder'] == $subfolder ? 'selected' : '').">- $subfolder</option>";
  797.                 }
  798.         }
  799.         return $all_subfolders;
  800. }
  801. ///////////////////////////
  802. //Function: dir_is_empty
  803. //Checks if dir is empty
  804. ///////////////////////////
  805. function dir_is_empty($path){
  806. $dir = opendir($path);
  807. $i = 0;
  808.         while ($files_in_subfolder = readdir($dir)) {
  809.                 if($files_in_subfolder != "." and $files_in_subfolder != ".." and $files_in_subfolder != "thumbs" and $files_in_subfolder != ".htaccess"){
  810.                         $i++;
  811.                 }
  812.         }
  813.         if($i == 0) return true;
  814.         else return false;
  815. }
  816.  
  817. ///////////////////////////
  818. //Function: create_htaccess
  819. //Creates a .htaccess file
  820. ///////////////////////////
  821. function create_htaccess($path_to_file){
  822.         if(!file_exists($path_to_file)){
  823.                 $ht_file = @fopen($path_to_file, w);
  824.                 $htaccess = "Order Deny,Allow\nAllow from all";
  825.                 @fwrite($ht_file, $htaccess);
  826.                 @fclose($path_to_file);
  827.         }
  828. }
  829.  
  830. //////////////////////
  831. //Function: make_thumb
  832. //Creates a thumbnail
  833. //////////////////////
  834. function make_thumb($src, $dest, $new_size, $way) {
  835. global $type;
  836.  
  837.                 $size = getimagesize($src);
  838.                 $img_width = $size[0];
  839.                 $img_height = $size[1];
  840.                
  841.                 if(($img_width > $new_size) or ($img_height > $new_size)){
  842.                         //Keep dimensions
  843.                         if($way == "normal"){
  844.                                 $ratio = $new_size/$img_width;
  845.                                 $new_width = $new_size;
  846.                                 $new_height = $img_height*$ratio;
  847.                                 $off_w = 0;
  848.                                 $off_h = 0;
  849.                         }
  850.                         //Crop
  851.                         else {
  852.                                 if($img_width > $img_height){
  853.                                         $new_width = $new_size;
  854.                                         $new_height = $new_size;
  855.                                         $off_w = ($img_width-$img_height)/2;
  856.                                         $off_h = 0;
  857.                                         $img_width = $img_height;
  858.                                 }
  859.                                 else if ($img_height > $img_width){
  860.                                         $new_width = $new_size;
  861.                                         $new_height = $new_size;
  862.                                         $off_w = 0;
  863.                                         $off_h = ($img_height - $img_width)/2;
  864.                                         $img_height = $img_width;
  865.                                 }
  866.                                 else{
  867.                                         $new_width = $new_size;
  868.                                         $new_height = $new_size;
  869.                                         $off_w = 0;
  870.                                         $off_h = 0;
  871.                                 }
  872.                         }
  873.                        
  874.                         if (strtolower($type) == "gif") {
  875.                                 $im_in = @imagecreatefromgif($src);
  876.                         }
  877.                         else {
  878.                                 $im_in = @imagecreatefromjpeg($src);
  879.                         }
  880.                         $im_out = @imagecreatetruecolor($new_width, $new_height);
  881.  
  882.                         @imagecopyresampled($im_out, $im_in, 0, 0, $off_w, $off_h, $new_width, $new_height, $img_width, $img_height);
  883.                 }
  884.                
  885.                 else {
  886.                         @copy($src, $dest);
  887.                 }
  888.  
  889.         if (strtolower($type) == "gif") {
  890.                 @imagegif($im_out, $dest);
  891.         }
  892.         else {
  893.                 @imagejpeg($im_out, $dest);
  894.         }
  895. }
  896.  
  897. ///////////////////////////
  898. //Function dropshadow
  899. //Adds a dropshadow to the thumb
  900. //Code taken from http://codewalkers.com/tutorials/83/1.html
  901. //////////////////////////////////
  902. function shadow($thumb_in) {
  903. global $type;
  904.  
  905. define("DS_OFFSET",      5);
  906. define("DS_STEPS", 10);
  907. define("DS_SPREAD", 1);
  908.  
  909. $background = array("r" => 255, "g" => 255, "b" => 255);
  910. list($o_width, $o_height) = getimagesize($thumb_in);
  911.  
  912.   $width  = $o_width + DS_OFFSET;
  913.   $height = $o_height + DS_OFFSET;
  914.   $image_sh = @imagecreatetruecolor($width, $height);
  915.  
  916. $step_offset = array("r" => ($background["r"] / DS_STEPS), "g" => ($background["g"] / DS_STEPS), "b" => ($background["b"] / DS_STEPS));
  917.  
  918.   $current_color = $background;
  919.   for ($i = 0; $i <= DS_STEPS; $i++) {
  920.         $colors[$i] = @imagecolorallocate($image_sh, round($current_color["r"]), round($current_color["g"]), round($current_color["b"]));
  921.  
  922.         $current_color["r"] -= $step_offset["r"];
  923.         $current_color["g"] -= $step_offset["g"];
  924.         $current_color["b"] -= $step_offset["b"];
  925.   }
  926. @imagefilledrectangle($image_sh, 0,0, $width, $height, $colors[0]);
  927.  
  928.  for ($i = 0; $i < count($colors); $i++) {
  929.         @imagefilledrectangle($image_sh, DS_OFFSET, DS_OFFSET, $width, $height, $colors[$i]);
  930.         $width -= DS_SPREAD;
  931.         $height -= DS_SPREAD;
  932.   }
  933.  
  934. if (strtolower($type) == "gif") {
  935. $original_image = @imagecreatefromgif($thumb_in);
  936. }
  937. else {
  938.  $original_image = @imagecreatefromjpeg($thumb_in);
  939.  }
  940.   @imagecopymerge($image_sh, $original_image, 0,0, 0,0, $o_width, $o_height, 100);
  941.  
  942.   if (strtolower($type) == "gif") {
  943. @imagegif($image_sh, $thumb_in);
  944. }
  945. else {
  946.   @imagejpeg($image_sh, $thumb_in);
  947.   }
  948. }
  949. /////////////////
  950. //Function Watermark
  951. //Code taken from http://edge.dev.box.sk/smsread.php?newsid=310
  952. ///////////////////
  953. function add_watermark($thumb_in,$text="[date]",$hotspot=8,$rgbtext="FFFFFF",$font_size=12,$font="Arial.TTF",$datfmt="d-m-Y",$rgbtsdw="000000",$txp=25,$typ=15,$sxp=1,$syp=1) {
  954.  
  955. $suffx=substr($thumb_in,strlen($thumb_in)-4,4);
  956. $suffx = strtolower($suffx);
  957. if ($suffx==".jpg" || $suffx=="jpeg" || $suffx==".png" || $suffx==".gif") {
  958. $text2 = $text;
  959. $text=str_replace("[date]",date($datfmt),$text);
  960.  
  961. if ($suffx==".jpg" || $suffx=="jpeg") {
  962. $image=imagecreatefromjpeg($thumb_in);
  963. }
  964. if ($suffx==".png") {
  965. $image=imagecreatefrompng($thumb_in);
  966. }
  967. if ($suffx == ".gif") {
  968. $image=imagecreatefromgif($thumb_in);
  969. }
  970.  
  971. $rgbtext=HexDec($rgbtext);
  972. $txtr=floor($rgbtext/pow(256,2));
  973. $txtg=floor(($rgbtext%pow(256,2))/pow(256,1));
  974. $txtb=floor((($rgbtext%pow(256,2))%pow(256,1))/pow(256,0));
  975.  
  976. $rgbtsdw=HexDec($rgbtsdw);
  977. $tsdr=floor($rgbtsdw/pow(256,2));
  978. $tsdg=floor(($rgbtsdw%pow(256,2))/pow(256,1));
  979. $tsdb=floor((($rgbtsdw%pow(256,2))%pow(256,1))/pow(256,0));
  980.  
  981. $coltext = imagecolorallocate($image,$txtr,$txtg,$txtb);
  982. $coltsdw = imagecolorallocate($image,$tsdr,$tsdg,$tsdb);
  983.  
  984. if ($hotspot!=0) {
  985. $ix=imagesx($image); $iy=imagesy($image); $tsw=($text2 == "[date]" ? strlen($text)+2 : strlen($text))*$font_size/imagefontwidth($font)*3; $tsh=$font_size/imagefontheight($font);
  986. switch ($hotspot) {
  987. case 1:
  988. $txp=$txp; $typ=$tsh*$tsh+imagefontheight($font)*2+$typ;
  989. break;
  990. case 2:
  991. $txp=floor(($ix-$tsw)/2); $typ=$tsh*$tsh+imagefontheight($font)*2+$typ;
  992. break;
  993. case 3:
  994. $txp=$ix-$tsw-$txp; $typ=$tsh*$tsh+imagefontheight($font)*2+$typ;
  995. break;
  996. case 4:
  997. $txp=$txp; $typ=floor(($iy-$tsh)/2);
  998. break;
  999. case 5:
  1000. $txp=floor(($ix-$tsw)/2); $typ=floor(($iy-$tsh)/2);
  1001. break;
  1002. case 6:
  1003. $txp=$ix-$tsw-$txp; $typ=floor(($iy-$tsh)/2);
  1004. break;
  1005. case 7:
  1006. $txp=$txp; $typ=$iy-$tsh-$typ;
  1007. break;
  1008. case 8:
  1009. $txp=floor(($ix-$tsw)/2); $typ=$iy-$tsh-$typ;
  1010. break;
  1011. case 9:
  1012. $txp=$ix-$tsw-$txp; $typ=$iy-$tsh-$typ;
  1013. break;
  1014. }
  1015. }
  1016.  
  1017. ImageTTFText($image,$font_size,0,$txp+$sxp,$typ+$syp,$coltsdw,$font,$text);
  1018. ImageTTFText($image,$font_size,0,$txp,$typ,$coltext,$font,$text);
  1019.  
  1020. if ($suffx==".jpg" || $suffx=="jpeg") {
  1021. imagejpeg($image, $thumb_in);
  1022. }
  1023. if ($suffx==".png") {
  1024. imagepng($image, $thumb_in);
  1025. }
  1026. if ($suffx == ".gif") {
  1027. imagegif($image, $thumb_in);
  1028. }
  1029. }
  1030. }
  1031. ////////////////////
  1032. //Function mergePix
  1033. //Taken from http://de3.php.net/manual/de/function.imagecopymerge.php
  1034. ///////////////////////
  1035. function mergePix($sourcefile,$insertfile, $targetfile, $pos=0,$transition=30)
  1036. {
  1037. //Get the resource id?s of the pictures
  1038. switch (strtolower(end(explode('.', $sourcefile))))
  1039.         {
  1040.                 case 'gif':
  1041.                         $sourcefile_id = imageCreateFromGIF($sourcefile);
  1042.                         break;
  1043.                 case 'jpg':
  1044.                         $sourcefile_id = imageCreateFromJPEG($sourcefile);
  1045.                         break;
  1046.                 case 'png':
  1047.                         $sourcefile_id = imageCreateFromPNG($sourcefile);
  1048.                         break;
  1049.         }
  1050. switch (strtolower(end(explode('.', $insertfile))))
  1051.         {
  1052.                 case 'gif':
  1053.                         $insertfile_id = imageCreateFromGIF($insertfile);
  1054.                         break;
  1055.                 case 'jpg':
  1056.                         $insertfile_id = imageCreateFromJPEG($insertfile);
  1057.                         break;
  1058.                 case 'png':
  1059.                         $insertfile_id = imageCreateFromPNG($insertfile);
  1060.                         break;
  1061.         }
  1062.  
  1063. //Get the sizes of both pix
  1064.         $sourcefile_width=imageSX($sourcefile_id);
  1065.         $sourcefile_height=imageSY($sourcefile_id);
  1066.         $insertfile_width=imageSX($insertfile_id);
  1067.         $insertfile_height=imageSY($insertfile_id);
  1068.  
  1069. //middle
  1070.         if( $pos == 0 )
  1071.         {
  1072.                 $dest_x = ( $sourcefile_width / 2 ) - ( $insertfile_width / 2 );
  1073.                 $dest_y = ( $sourcefile_height / 2 ) - ( $insertfile_height / 2 );
  1074.         }
  1075.  
  1076. //top left
  1077.                 if( $pos == 1 )
  1078.                 {
  1079.                                 $dest_x = 10;
  1080.                                 $dest_y = 10;
  1081.                 }
  1082.  
  1083. //top right
  1084.                 if( $pos == 2 )
  1085.                 {
  1086.                                 $dest_x = $sourcefile_width - $insertfile_width - 10;
  1087.                                 $dest_y = 10;
  1088.                 }
  1089.  
  1090. //bottom right
  1091.                 if( $pos == 3 )
  1092.                 {
  1093.                                 $dest_x = $sourcefile_width - $insertfile_width - 10;
  1094.                                 $dest_y = $sourcefile_height - $insertfile_height - 10;
  1095.                 }
  1096.  
  1097. //bottom left
  1098.                 if( $pos == 4 )
  1099.                 {
  1100.                                 $dest_x = 10;
  1101.                                 $dest_y = $sourcefile_height - $insertfile_height - 10;
  1102.                 }
  1103.  
  1104. //top middle
  1105.                 if( $pos == 5 )
  1106.                 {
  1107.                                 $dest_x = ( ( $sourcefile_width - $insertfile_width ) / 2 );
  1108.                                 $dest_y = 10;
  1109.                 }
  1110.  
  1111. //middle right
  1112.                 if( $pos == 6 )
  1113.                 {
  1114.                                 $dest_x = $sourcefile_width - $insertfile_width - 10;
  1115.                                 $dest_y = ( $sourcefile_height / 2 ) - ( $insertfile_height / 2 );
  1116.                 }
  1117.  
  1118. //bottom middle
  1119.                 if( $pos == 7 )
  1120.                 {
  1121.                                 $dest_x = ( ( $sourcefile_width - $insertfile_width ) / 2 );
  1122.                                 $dest_y = $sourcefile_height - $insertfile_height - 10;
  1123.                 }
  1124.  
  1125. //middle left
  1126.                 if( $pos == 8 )
  1127.                 {
  1128.                                 $dest_x = 10;
  1129.                                 $dest_y = ( $sourcefile_height / 2 ) - ( $insertfile_height / 2 );
  1130.                 }
  1131.  
  1132. //The main thing : merge the two pix
  1133.         imageCopyMerge($sourcefile_id, $insertfile_id,$dest_x,$dest_y,0,0,$insertfile_width,$insertfile_height,$transition);
  1134.  
  1135. //Create a jpeg/gif/png out of the modified picture
  1136. switch (strtolower(end(explode('.', $sourcefile))))
  1137.         {
  1138.                 case 'gif':
  1139.                         imagegif ($sourcefile_id,"$targetfile");
  1140.                         break;
  1141.                 case 'jpg':
  1142.                         imagejpeg ($sourcefile_id,"$targetfile");
  1143.                         break;
  1144.                 case 'png':
  1145.                         imagepng ($sourcefile_id,"$targetfile");
  1146.                         break;
  1147.         }
  1148.  
  1149. }
  1150.  
  1151. /** ------------------------------------------------------------
  1152.  * Copy and resample an image with rounded corners.
  1153.  * by Michael Shipanski
  1154.  * Taken from http://ru2.php.net/manual/de/function.imagecopyresampled.php#80417
  1155.  * Modified by FI-DD
  1156.  * ----------------------------------------------------------- */
  1157. function roundedCorners($src, $radius, $color) {
  1158. global $type;
  1159.        
  1160.         switch (strtolower($type))
  1161.         {
  1162.                 case 'gif':
  1163.                         $srcimg = imageCreateFromGIF($src);
  1164.                         break;
  1165.                 case 'jpg':
  1166.                         $srcimg = imageCreateFromJPEG($src);
  1167.                         break;
  1168.                 case 'jpeg':
  1169.                         $srcimg = imageCreateFromJPEG($src);
  1170.                         break;
  1171.                 case 'png':
  1172.                         $srcimg = imageCreateFromPNG($src);
  1173.                         break;
  1174.         }
  1175.        
  1176.         $width = imagesx($srcimg);
  1177.         $height = imagesy($srcimg);
  1178.        
  1179.         $dstimg = imagecreatetruecolor($width, $height);
  1180.         $bg = imagecolorallocate($dstimg, hexdec($color{0}.$color{1}),hexdec($color{2}.$color{3}),hexdec($color{4}.$color{5}));
  1181.         imagefill($dstimg,0,0,$bg);
  1182.  
  1183.         $srcResized = imagecreatetruecolor($width, $height);
  1184.         imagecopyresampled($srcResized, $srcimg, 0, 0, 0, 0,
  1185.                                            $width, $height, $width, $height);
  1186.  
  1187.         imagecopy($dstimg, $srcResized, 0+$radius, 0,
  1188.                           $radius, 0, $width-($radius*2), $height);
  1189.         imagecopy($dstimg, $srcResized, 0, 0+$radius,
  1190.                           0, $radius, $width, $height-($radius*2));
  1191.  
  1192.         $iterations = array(
  1193.                 array(0, 0, $radius, $radius),
  1194.                 array($width-$radius, 0, $width-$radius, $radius),
  1195.                 array(0, $height-$radius, $radius, $height-$radius),
  1196.                 array($width-$radius, $height-$radius, $width-$radius, $height-$radius)
  1197.         );
  1198.         foreach($iterations as $iteration) {
  1199.                 list($x1,$y1,$cx,$cy) = $iteration;
  1200.                 for ($y=$y1; $y<=$y1+$radius; $y++) {
  1201.                         for ($x=$x1; $x<=$x1+$radius; $x++) {
  1202.                                 $length = sqrt(pow(($cx - $x), 2) + pow(($cy - $y), 2));
  1203.                                 if ($length < $radius) {
  1204.                                         imagecopy($dstimg, $srcResized, $x+0, $y+0,
  1205.                                                           $x, $y, 1, 1);
  1206.                                 }
  1207.                         }
  1208.                 }
  1209.         }
  1210.        
  1211.         switch (strtolower($type))
  1212.         {
  1213.                 case 'gif':
  1214.                         imagegif ($dstimg, $src);
  1215.                         break;
  1216.                 case 'jpg':
  1217.                         imagejpeg ($dstimg, $src, 100);
  1218.                         break;
  1219.                 case 'jpeg':
  1220.                         imagejpeg ($dstimg, $src, 100);
  1221.                         break;
  1222.                 case 'png':
  1223.                         imagepng ($dstimg, $src);
  1224.                         break;
  1225.         }
  1226.        
  1227. }
  1228. ?>