ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilImagemapPreview Class Reference

Image map image preview creator. More...

+ Collaboration diagram for ilImagemapPreview:

Public Member Functions

 __construct ($imagemap_filename="")
 ilImagemapPreview constructor More...
 
 getAreaCount ()
 
 getPointCount ()
 
 addArea ( $index, $shape, $coords, $title="", $href="", $target="", $visible=true, $linecolor="red", $bordercolor="white", $fillcolor="#FFFFFFA0")
 
 addPoint ( $index, $coords, $visible=true, $linecolor="red", $bordercolor="white", $fillcolor="#FFFFFFA0")
 
 getAreaIdent ()
 
 createPreview ()
 
 getPreviewFilename ($imagePath, $baseFileName)
 
 getImagemap ($title)
 get imagemap html code note: html code should be placed in template files More...
 

Data Fields

 $imagemap_filename
 
 $preview_filename
 
 $areas
 
 $points
 
 $linewidth_outer
 
 $linewidth_inner
 
 $lng
 

Detailed Description

Image map image preview creator.

Takes an image and imagemap areas and creates a preview image containing the imagemap areas.

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Version
$Id$

Definition at line 16 of file class.ilImagemapPreview.php.

Constructor & Destructor Documentation

◆ __construct()

ilImagemapPreview::__construct (   $imagemap_filename = "")

ilImagemapPreview constructor

Creates an instance of the ilImagemapPreview class

Parameters
integer$idThe database id of a image map question object public

Definition at line 34 of file class.ilImagemapPreview.php.

References $imagemap_filename, $lng, $preview_filename, array, and ilUtil\ilTempnam().

35  {
36  global $lng;
37  $this->lng =& $lng;
38  $this->imagemap_filename = $imagemap_filename;
39  $this->preview_filename = $preview_filename;
40  if (!@is_file($this->preview_filename))
41  {
42  $extension = ".jpg";
43  if (preg_match("/.*\.(png|jpg|gif|jpeg)$/", $this->imagemap_filename, $matches))
44  {
45  $extension = "." . $matches[1];
46  }
47  include_once "./Services/Utilities/classes/class.ilUtil.php";
48  $this->preview_filename = ilUtil::ilTempnam() . $extension;
49  }
50  $this->areas = array();
51  $this->points = array();
52  $this->linewidth_outer = 4;
53  $this->linewidth_inner = 2;
54  }
Create styles array
The data for the language used.
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable directory.
+ Here is the call graph for this function:

Member Function Documentation

◆ addArea()

ilImagemapPreview::addArea (   $index,
  $shape,
  $coords,
  $title = "",
  $href = "",
  $target = "",
  $visible = true,
  $linecolor = "red",
  $bordercolor = "white",
  $fillcolor = "#FFFFFFA0" 
)

Definition at line 66 of file class.ilImagemapPreview.php.

References array.

78  {
79  if (ini_get("safe_mode"))
80  {
81  if ((strpos($fillcolor, "#") !== false) || (strpos($fillcolor, "rgb") !== false))
82  {
83  $fillcolor = str_replace("\"", "", $fillcolor);
84  }
85  }
86  $this->areas[$index] = array(
87  "shape" => "$shape",
88  "coords" => "$coords",
89  "title" => "$title",
90  "href" => "$href",
91  "target" => "$target",
92  "linecolor" => '"' . $linecolor . '"',
93  "fillcolor" => '"' . $fillcolor . '"',
94  "bordercolor" => '"' . $bordercolor . '"',
95  "visible" => (int)$visible
96  );
97  }
Create styles array
The data for the language used.

◆ addPoint()

ilImagemapPreview::addPoint (   $index,
  $coords,
  $visible = true,
  $linecolor = "red",
  $bordercolor = "white",
  $fillcolor = "#FFFFFFA0" 
)

Definition at line 99 of file class.ilImagemapPreview.php.

References array.

107  {
108  $this->points[$index] = array(
109  "coords" => "$coords",
110  "linecolor" => '"' . $linecolor . '"',
111  "fillcolor" => '"' . $fillcolor . '"',
112  "bordercolor" => '"' . $bordercolor . '"',
113  "visible" => (int)$visible
114  );
115  }
Create styles array
The data for the language used.

◆ createPreview()

ilImagemapPreview::createPreview ( )

Definition at line 136 of file class.ilImagemapPreview.php.

References $r, $target, $x, $y, ilUtil\escapeShellCmd(), and ilUtil\execConvert().

137  {
138  if (count($this->areas)+count($this->points)==0) return;
139  include_once "./Services/Utilities/classes/class.ilUtil.php";
140  $convert_cmd = "-quality 100 ";
141  foreach ($this->points as $point)
142  {
143  if ($point["visible"])
144  {
145  preg_match("/(\d+)\s*,\s*(\d+)/", $point["coords"], $matches);
146  $x = $matches[1];
147  $y = $matches[2];
148  $r = 6;
149  // draw a circle at the point
150  $convert_cmd .= "-stroke " . $point["bordercolor"] . " -fill " . $point["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"line " .
151  ($x-$r) . "," . ($y-$r) . " " . ($x+$r) . "," . ($y+$r) . "\" " .
152  "-stroke " . $point["bordercolor"] . " -fill " . $point["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"line " .
153  ($x+$r) . "," . ($y-$r) . " " . ($x-$r) . "," . ($y+$r) . "\" " .
154  "-stroke " . $point["linecolor"] . " -fill " . $point["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"line " .
155  ($x-$r) . "," . ($y-$r) . " " . ($x+$r) . "," . ($y+$r) . "\" " .
156  "-stroke " . $point["linecolor"] . " -fill " . $point["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"line " .
157  ($x+$r) . "," . ($y-$r) . " " . ($x-$r) . "," . ($y+$r) . "\" ";
158  }
159  }
160  foreach ($this->areas as $area)
161  {
162  if ($area["visible"] and strcmp(strtolower($area["shape"]), "rect") == 0)
163  {
164  preg_match("/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area["coords"], $matches);
165  $x0 = $matches[1];
166  $y0 = $matches[2];
167  $x1 = $matches[3];
168  $y1 = $matches[4];
169  // draw a rect around the selection
170  $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"rectangle " .
171  $x0 . "," . $y0 . " " . ($x1) . "," . $y1 . "\" " .
172  "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"rectangle " .
173  $x0 . "," . $y0 . " " . ($x1) . "," . $y1 . "\" ";
174  }
175  else if ($area["visible"] and strcmp(strtolower($area["shape"]), "circle") == 0)
176  {
177  preg_match("/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area["coords"], $matches);
178  $x = $matches[1];
179  $y = $matches[2];
180  $r = $matches[3];
181  // draw a circle around the selection
182  $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"circle " .
183  $x . "," . $y . " " . ($x+$r) . "," . $y . "\" " .
184  "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"circle " .
185  $x . "," . $y . " " . ($x+$r) . "," . $y . "\" ";
186  }
187  else if ($area["visible"] and strcmp(strtolower($area["shape"]), "poly") == 0)
188  {
189  $obj = "polygon";
190  // draw a polygon around the selection
191  preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
192  if (count($matches[0]) == 2) $obj = "line";
193  $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"$obj ";
194  for ($i = 0; $i < count($matches[0]); $i++)
195  {
196  $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " ";
197  }
198  $convert_cmd .= "\" ";
199  $convert_cmd .= "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"$obj ";
200  preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
201  for ($i = 0; $i < count($matches[0]); $i++)
202  {
203  $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " ";
204  }
205  $convert_cmd .= "\" ";
206  }
207  }
208 
209  $source = ilUtil::escapeShellCmd($this->imagemap_filename);
210  $target = ilUtil::escapeShellCmd($this->preview_filename);
211  $convert_cmd = $source . "[0] " . $convert_cmd." ".$target;
212  ilUtil::execConvert($convert_cmd);
213  }
$x
Definition: example_009.php:98
static escapeShellCmd($a_arg)
escape shell cmd
$r
Definition: example_031.php:79
$y
Definition: example_007.php:83
static execConvert($args)
execute convert command
+ Here is the call graph for this function:

◆ getAreaCount()

ilImagemapPreview::getAreaCount ( )

Definition at line 56 of file class.ilImagemapPreview.php.

57  {
58  return count($this->areas);
59  }

◆ getAreaIdent()

ilImagemapPreview::getAreaIdent ( )

Definition at line 117 of file class.ilImagemapPreview.php.

Referenced by getPreviewFilename().

118  {
119  if (count($this->areas)+count($this->points) > 0)
120  {
121  $arr = array_merge(array_keys($this->areas), array_keys($this->points));
122  sort($arr, SORT_NUMERIC);
123 
124  $inner = join("_", $arr);
125  if (strlen($inner) > 32) {
126  $inner = md5($inner);
127  }
128  return "preview_" . $inner . "_";
129  }
130  else
131  {
132  return "";
133  }
134  }
+ Here is the caller graph for this function:

◆ getImagemap()

ilImagemapPreview::getImagemap (   $title)

get imagemap html code note: html code should be placed in template files

Definition at line 254 of file class.ilImagemapPreview.php.

255  {
256  $map = "<map name=\"$title\"> ";
257  foreach ($this->areas as $area)
258  {
259  $map .= "<area alt=\"" . $area["title"] . "\" title=\"" . $area["title"] . "\" ";
260  $map .= "shape=\"" . $area["shape"] . "\" ";
261  $map .= "coords=\"" . $area["coords"] . "\" ";
262  if ($area["href"])
263  {
264  $map .= "href=\"" . $area["href"] . "\" ";
265  if ($area["target"])
266  {
267  $map .= "target=\"" . $area["target"] . "\" ";
268  }
269  $map .= "/>\n";
270  }
271  else
272  {
273  $map .= "nohref />\n";
274  }
275  }
276  $map .= "</map>";
277  return $map;
278  }

◆ getPointCount()

ilImagemapPreview::getPointCount ( )

Definition at line 61 of file class.ilImagemapPreview.php.

62  {
63  return count($this->points);
64  }

◆ getPreviewFilename()

ilImagemapPreview::getPreviewFilename (   $imagePath,
  $baseFileName 
)

Definition at line 215 of file class.ilImagemapPreview.php.

References $filename, $preview_filename, getAreaIdent(), and ilUtil\sendInfo().

216  {
217  $filename = $baseFileName;
218  if (count($this->areas)+count($this->points)>0)
219  {
220  $pfile = $this->preview_filename;
221  if (is_file($pfile))
222  {
223  $ident = $this->getAreaIdent();
224  $previewfile = $imagePath . $ident . $baseFileName;
225  if (@md5_file($previewfile) != @md5_file($pfile))
226  {
227  if (strlen($ident) > 0)
228  {
229  @copy($pfile, $previewfile);
230  }
231  }
232  @unlink($pfile);
233  if (strlen($pfile) == 0)
234  {
235  ilUtil::sendInfo($this->lng->txt("qpl_imagemap_preview_missing"));
236  }
237  else
238  {
239  $filename = basename($previewfile);
240  }
241  }
242  else
243  {
244  ilUtil::sendInfo($this->lng->txt("qpl_imagemap_preview_missing"));
245  }
246  }
247  return $filename;
248  }
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
+ Here is the call graph for this function:

Field Documentation

◆ $areas

ilImagemapPreview::$areas

Definition at line 20 of file class.ilImagemapPreview.php.

◆ $imagemap_filename

ilImagemapPreview::$imagemap_filename

Definition at line 18 of file class.ilImagemapPreview.php.

Referenced by __construct().

◆ $linewidth_inner

ilImagemapPreview::$linewidth_inner

Definition at line 23 of file class.ilImagemapPreview.php.

◆ $linewidth_outer

ilImagemapPreview::$linewidth_outer

Definition at line 22 of file class.ilImagemapPreview.php.

◆ $lng

ilImagemapPreview::$lng

Definition at line 24 of file class.ilImagemapPreview.php.

Referenced by __construct().

◆ $points

ilImagemapPreview::$points

Definition at line 21 of file class.ilImagemapPreview.php.

◆ $preview_filename

ilImagemapPreview::$preview_filename

Definition at line 19 of file class.ilImagemapPreview.php.

Referenced by __construct(), and getPreviewFilename().


The documentation for this class was generated from the following file: