/test/image.php

https://github.com/Certun/ExtJS-Themer · PHP · 95 lines · 80 code · 2 blank · 13 comment · 9 complexity · ada9271e15bf3128a8a81509d8a41921 MD5 · raw file

  1. <?php
  2. /**
  3. * Created by JetBrains PhpStorm.
  4. * User: Ernesto J Rodriguez (Certun)
  5. * Date: 10/9/11
  6. * Time: 9:23 PM
  7. * @param string $path
  8. * @param int $level
  9. * @internal param $im
  10. * @internal param $red
  11. * @internal param $green
  12. * @internal param $blue
  13. * @return void
  14. */
  15. function getDirectory( $path = '.', $level = 0 ){
  16. $ignore = array( 'cgi-bin', '.', '..' ); //<<-------------------// Directories to ignore when listing output. Many hosts will deny PHP access to the cgi-bin.
  17. $dh = @opendir( $path ); //<<-----------------------------------// Open the directory to the handle $dh
  18. while( false !== ( $file = readdir( $dh ) ) ){ //<<-------------// Loop through the directory
  19. if( !in_array( $file, $ignore ) ){ //<<---------------------// Check that this file is not to be ignored
  20. $spaces = str_repeat( '&nbsp;', ( $level * 4 ) ); //<<--// Just to add spacing to the list, to better show the directory tree
  21. if( is_dir( "$path/$file" ) ){ //<<---------------------// Its a directory, so we need to keep reading down...
  22. echo "<br /><strong>$path $file</strong> (DIR)<br />";
  23. getDirectory( "$path/$file", ($level+1) ); //<<-----// Re-call this same function but on a new directory. this is what makes function recursive.
  24. } else {
  25. echo "$path $file<br />"; //<<----------------------// Just print out the filename for now!
  26. }
  27. }
  28. }
  29. closedir( $dh ); // Close the directory handle
  30. }
  31. if ($_POST){
  32. function ImageSelectiveColor($im,$red,$green,$blue){
  33. for( $i=0 ; $i<imagecolorstotal($im) ; $i++){
  34. $col = ImageColorsForIndex($im,$i);
  35. $red_set = $red / 150 * $col['red'];
  36. $green_set = $green / 150 * $col['green'];
  37. $blue_set = $blue / 150 * $col['blue'];
  38. if($red_set>255) $red_set = 255;
  39. if($green_set>255) $green_set = 255;
  40. if($blue_set>255) $blue_set = 255;
  41. imagecolorset($im,$i,$red_set,$green_set,$blue_set);
  42. }
  43. return $im;
  44. }
  45. $imgname = "test.gif";
  46. $im = imagecreatefromgif($imgname);
  47. if(isset($_POST['1'])){
  48. $r = 30;
  49. $g = 115;
  50. $b = 115;
  51. } elseif(isset($_POST['2'])){
  52. $r = 115;
  53. $g = 30;
  54. $b = 115;
  55. } elseif(isset($_POST['3'])){
  56. $r = 115;
  57. $g = 115;
  58. $b = 30;
  59. } elseif(isset($_POST['4'])){
  60. $r = 190;
  61. $g = 20;
  62. $b = 150;
  63. } elseif(isset($_POST['5'])){
  64. $r = 75;
  65. $g = 110;
  66. $b = 190;
  67. }
  68. $im = ImageSelectiveColor($im,$r,$g,$b);
  69. $imgname = "result.gif";
  70. imagegif($im, $imgname ); // save image as gif
  71. imagedestroy($im);
  72. header('Location: image.php');
  73. }
  74. ?>
  75. <html>
  76. <head></head>
  77. <body>
  78. <form id="color" action="" method="POST">
  79. <input type="submit" value="submit" name="1" />
  80. <input type="submit" value="submit" name="2" />
  81. <input type="submit" value="submit" name="3" />
  82. <input type="submit" value="submit" name="4" />
  83. <input type="submit" value="submit" name="5" />
  84. </form>
  85. <br/><br/>
  86. <img src="test.gif" alt="" />
  87. <img src="result.gif?<?php echo rand(5, 1000) ?>" alt="" />
  88. <br/><br/>
  89. <h2>This is to test the getDirectory funtion</h2>
  90. <p>This funtion will read all the file inste the images dir to then GD the images</p>
  91. <?php getDirectory( "../theme_templates/default/resources/themes/images" ); ?>
  92. </body>
  93. </html>