PHP Classes

File: ImageFragmentator.tests.php

Recommend this page to a friend!
  Classes of Juraj 'Puerdraco' Hajdúch   PHP Image Fragmentator   ImageFragmentator.tests.php   Download  
File: ImageFragmentator.tests.php
Role: Example script
Content type: text/plain
Description: Testing developer script, simple GUI.
Class: PHP Image Fragmentator
Create a tile view of an image of given size
Author: By
Last change:
Date: 10 years ago
Size: 8,047 bytes
 

Contents

Class file image Download
<?php
include_once(dirname(__FILE__).DIRECTORY_SEPARATOR."ImageFragmentator.classmini.php");
$ins = new ImageFragmentator;

if(isset(
$_GET["ff_file"])){
 
$ins->ifReturn($_GET["ff_file"], $_GET["ff_width"], $_GET["ff_height"], $_GET["ff_row"], $_GET["ff_column"]);
  exit;
}

echo
"<h1>PHP class ImageFragmentator tests page</h1>".PHP_EOL;

echo
"<h2>Settings formular:</h2>".PHP_EOL;

echo
"<form method=\"post\" action=\"\" enctype=\"multipart/form-data\">".PHP_EOL;
echo
"#1 select input mime type ";
echo
"(of this image <img src=\"./ImageFragmentator.testimage.jpg\" width=\"40\" alt=\"[FILE NOT FOUND]\" />, 200 &times; 300 px) ";
echo
"<input type=\"radio\" name=\"ff_file\" value=\"jpg\" checked=\"checked\" /> JPG";
echo
"<input type=\"radio\" name=\"ff_file\" value=\"png\" /> PNG";
echo
"<input type=\"radio\" name=\"ff_file\" value=\"gif\" /> GIF ";
echo
"or select from PC <input type=\"file\" name=\"ff_file_pc\" />";
echo
"<br />";
echo
"#2 set width ";
echo
"<select name=\"ff_width\">";
echo
"<option value=\"0\">0 (full width)</option>";
echo
"<option value=\"1\">1</option>";
for(
$i = 5; $i <= 350; $i = $i + 5){
  if(
$i == 100){
   
$selected = " selected=\"selected\"";
  }
  else{
      
$selected = "";
  }
  echo
"<option value=\"".$i."\"".$selected.">".$i."</option>";
}
echo
"</select>";
echo
" and height ";
echo
"<select name=\"ff_height\">";
echo
"<option value=\"0\">0 (full height)</option>";
echo
"<option value=\"1\">1</option>";
for(
$i = 5; $i <= 350; $i = $i + 5){
  if(
$i == 100){
   
$selected = " selected=\"selected\"";
  }
  else{
      
$selected = "";
  }
  echo
"<option value=\"".$i."\"".$selected.">".$i."</option>";
}
echo
"</select>";
echo
" of fragment(s)";
echo
"<br />";
echo
"#3 select output mime type ";
echo
"<input type=\"radio\" name=\"ff_output\" value=\"image/jpeg\" checked=\"checked\" /> JPG";
echo
"<input type=\"radio\" name=\"ff_output\" value=\"image/png\" /> PNG";
echo
"<input type=\"radio\" name=\"ff_output\" value=\"image/gif\" /> GIF";
echo
"<br />";
echo
"#4 select action ";
echo
"<select name=\"ff_action\">";
echo
"<option value=\"save\" selected=\"selected\">save all fragments</option>";
echo
"<option value=\"return\">return one fragment</option>";
echo
"</select> ";
echo
"<br />";
echo
"(if save all fragments that with name ";
echo
"<input type=\"text\" name=\"ff_pattern\" value=\"ImageFragmentator.resultimage.[pc]\" />)";
echo
"<br />";
echo
"(if return one fragment that by order ";
echo
"<select name=\"ff_order\">";
echo
"<option value=\"0\">- - -</option>";
for(
$i = 1; $i <= 100; $i++){
  echo
"<option value=\"".$i."\">".$i."</option>";
}
echo
"</select>";
echo
" or by row ";
echo
"<select name=\"ff_row\">";
echo
"<option value=\"0\">- - -</option>";
for(
$i = 1; $i <= 10; $i++){
  echo
"<option value=\"".$i."\">".$i."</option>";
}
echo
"</select>";
echo
" and ";
echo
"<select name=\"ff_column\">";
echo
"<option value=\"0\">- - -</option>";
for(
$i = 1; $i <= 10; $i++){
  echo
"<option value=\"".$i."\">".$i."</option>";
}
echo
"</select>";
echo
")";
echo
"<br />";
echo
"#5 turn <input type=\"checkbox\" name=\"ff_overflow\" /> overflow if need ";
echo
"and turn <input type=\"checkbox\" name=\"ff_cut\" /> overflow cut if you want ";
echo
"(background color <input type=\"color\" name=\"ff_color\" value=\"#dddddd\" />, ";
echo
"<input type=\"checkbox\" name=\"ff_transparent\" /> gif/png transparent)";
echo
"<br />";
echo
"<input type=\"submit\" value=\"run test\" />";
echo
"</form>";

echo
"<h2>Result:</h2>".PHP_EOL;

if(isset(
$_POST["ff_file"]) || isset($_POST["ff_file_pc"])){
 
$code_buffer = "// PHP code<br />";
 
$code_buffer .= "include_once(\"ImageFragmentator.class.php\");<br />";
 
$code_buffer .= "&dollar;i = new ImageFragmentator;<br />";
  echo
"<table>";
  echo
"<tr><td>ORIGINAL FILE<br />&nbsp;</td><td>FRAGMENT(S)<br />style=\"border: 1px solid #00ff00;\"</td><td>INFORMATIONS<br />&dollar;key = &dollar;value</td></tr>";
  echo
"<tr>";
  echo
"<td style=\"vertical-align: top;\">";
 
//var_dump($_FILES);

 
if(isset($_FILES["ff_file_pc"]) && $_FILES["ff_file_pc"]["error"] != 4){
   
$name = $_FILES["ff_file_pc"]["name"];
   
move_uploaded_file($_FILES["ff_file_pc"]["tmp_name"], $name);
  }
  else{
   
$name = "./ImageFragmentator.testimage.".$_POST["ff_file"];
  }
 
//echo $name;

 
echo "<img src=\"".$name."\" alt=\"[FILE NOT FOUND]\" />";
  echo
"</td>";
  echo
"<td style=\"vertical-align: top;\">";
 
$ins->ifSetFragmentsMimeType($_POST["ff_output"]);
 
$code_buffer .= "&dollar;i->ifSetFragmentsMimeType(\"".$_POST["ff_output"]."\"); // default is \"image/jpeg\"<br />";
  if(isset(
$_POST["ff_overflow"])){
   
$ins->ifSetOverflow($_POST["ff_overflow"]);
   
$code_buffer .= "&dollar;i->ifSetOverflow(\"".$_POST["ff_overflow"]."\"); // default is false<br />";
  }
  if(isset(
$_POST["ff_cut"])){
   
$ins->ifSetOverflowCut($_POST["ff_cut"]);
   
$code_buffer .= "&dollar;i->ifSetOverflowCut(\"".$_POST["ff_cut"]."\"); // default is false<br />";
  }
  if(isset(
$_POST["ff_transparent"])){
   
$ins->ifSetOverflowAlpha($_POST["ff_transparent"]);
   
$code_buffer .= "&dollar;i->ifSetOverflowAlpha(\"".$_POST["ff_transparent"]."\"); // default is false<br />";
  }
 
$ins->ifSetOverflowColor($_POST["ff_color"]);
 
$code_buffer .= "&dollar;i->ifSetOverflowColor(\"".$_POST["ff_color"]."\"); // default is '000000'<br />";

  if(
$_POST["ff_action"] === "save"){
   
$ins->ifSave($name, $_POST["ff_width"], $_POST["ff_height"], $_POST["ff_pattern"]);
   
$code_buffer .= "&dollar;i->ifSave(\"".$name."\", ".$_POST["ff_width"].", ".$_POST["ff_height"].", \"".$_POST["ff_pattern"]."\");<br />";
   
$info = $ins->ifGetInfo();
    foreach(
$info["fragments-paths"] as $key => $value){
      echo
"<img src=\"".$value."\" alt=\"[ERROR]\" title=\"".$value."\" style=\"border: 1px solid #00ff00; margin: 2px;\" />";
      if((
$key + 1) % $info["fragments-x"] === 0){
        echo
"<br />";
      }
    }
    echo
"list of files:<br />";
    foreach(
$info["fragments-paths"] as $value){
      echo
$value."<br />";
    }
  }
  else{
   
$file = explode(DIRECTORY_SEPARATOR, __FILE__);
   
$file = end($file);
   
$row = 0;
   
$column = 0;
   
// by order
   
if($_POST["ff_order"] != 0){
     
$row = $_POST["ff_order"]; // because if exist only row that row is order number
      //echo $name;
     
echo "<img src=\"".$file."?ff_file=".$name."&ff_width=".$_POST["ff_width"]."&ff_height=".$_POST["ff_height"]."&ff_row=".$row."&ff_column=".$column."\" style=\"border: 1px solid #00ff00;\" />";
     
$code_buffer .= "&dollar;i->ifReturn(\"".$name."\", ".$_POST["ff_width"].", ".$_POST["ff_height"].", ".$row.");<br />";
    }
    else{
     
// by row and column
     
if(($_POST["ff_row"] != 0) && ($_POST["ff_column"] != 0)){
       
$row = $_POST["ff_row"];
       
$column = $_POST["ff_column"];
        echo
"<img src=\"".$file."?ff_file=".$name."&ff_width=".$_POST["ff_width"]."&ff_height=".$_POST["ff_height"]."&ff_row=".$row."&ff_column=".$column."\" />";
       
$code_buffer .= "&dollar;i->ifReturn(\"".$name."\", ".$_POST["ff_width"].", ".$_POST["ff_height"].", ".$row.", ".$column.");<br />";

      }
      else{

        echo
"By careful!<br />If you selected 'return one fragment' action<br />and you not selected 'order'<br />must by selected 'row' and 'column'.<br />";
      }
    }
    echo
"<br />";
  }
  echo
"</td>";
  echo
"<td style=\"vertical-align: top;\">";

 
$info = $ins->ifGetInfo();
  foreach(
$info as $k => $v){
    if(!
is_array($v)){
      echo
$k." = ".$v."<br />";
    }
  }
  echo
"<dir style=\"font-size: 10px; font-family: 'Courier New', Courier, monospace; Border: 1px solid #000000; padding: 5px; background-color: #dddddd;\">";
  echo
$code_buffer;
  echo
"</dir>";
  echo
"</td>";
  echo
"</tr>";
  echo
"</table>";
}
else{
  echo
"Not result. Please use settings formular.";
}

?>