ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  $extension = ".jpg";
42  if (preg_match("/.*\.(png|jpg|gif|jpeg)$/", $this->imagemap_filename, $matches)) {
43  $extension = "." . $matches[1];
44  }
45  include_once "./Services/Utilities/classes/class.ilUtil.php";
46  $this->preview_filename = ilUtil::ilTempnam() . $extension;
47  }
48  $this->areas = array();
49  $this->points = array();
50  $this->linewidth_outer = 4;
51  $this->linewidth_inner = 2;
52  }
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 64 of file class.ilImagemapPreview.php.

References $index, and array.

75  {
76  if (ini_get("safe_mode")) {
77  if ((strpos($fillcolor, "#") !== false) || (strpos($fillcolor, "rgb") !== false)) {
78  $fillcolor = str_replace("\"", "", $fillcolor);
79  }
80  }
81  $this->areas[$index] = array(
82  "shape" => "$shape",
83  "coords" => "$coords",
84  "title" => "$title",
85  "href" => "$href",
86  "target" => "$target",
87  "linecolor" => '"' . $linecolor . '"',
88  "fillcolor" => '"' . $fillcolor . '"',
89  "bordercolor" => '"' . $bordercolor . '"',
90  "visible" => (int) $visible
91  );
92  }
$index
Definition: metadata.php:60
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 94 of file class.ilImagemapPreview.php.

References $index, and array.

101  {
102  $this->points[$index] = array(
103  "coords" => "$coords",
104  "linecolor" => '"' . $linecolor . '"',
105  "fillcolor" => '"' . $fillcolor . '"',
106  "bordercolor" => '"' . $bordercolor . '"',
107  "visible" => (int) $visible
108  );
109  }
$index
Definition: metadata.php:60
Create styles array
The data for the language used.

◆ createPreview()

ilImagemapPreview::createPreview ( )

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

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

128  {
129  if (count($this->areas)+count($this->points)==0) {
130  return;
131  }
132  include_once "./Services/Utilities/classes/class.ilUtil.php";
133  $convert_cmd = "-quality 100 ";
134  foreach ($this->points as $point) {
135  if ($point["visible"]) {
136  preg_match("/(\d+)\s*,\s*(\d+)/", $point["coords"], $matches);
137  $x = $matches[1];
138  $y = $matches[2];
139  $r = 6;
140  // draw a circle at the point
141  $convert_cmd .= "-stroke " . $point["bordercolor"] . " -fill " . $point["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"line " .
142  ($x-$r) . "," . ($y-$r) . " " . ($x+$r) . "," . ($y+$r) . "\" " .
143  "-stroke " . $point["bordercolor"] . " -fill " . $point["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"line " .
144  ($x+$r) . "," . ($y-$r) . " " . ($x-$r) . "," . ($y+$r) . "\" " .
145  "-stroke " . $point["linecolor"] . " -fill " . $point["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"line " .
146  ($x-$r) . "," . ($y-$r) . " " . ($x+$r) . "," . ($y+$r) . "\" " .
147  "-stroke " . $point["linecolor"] . " -fill " . $point["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"line " .
148  ($x+$r) . "," . ($y-$r) . " " . ($x-$r) . "," . ($y+$r) . "\" ";
149  }
150  }
151  foreach ($this->areas as $area) {
152  if ($area["visible"] and strcmp(strtolower($area["shape"]), "rect") == 0) {
153  preg_match("/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area["coords"], $matches);
154  $x0 = $matches[1];
155  $y0 = $matches[2];
156  $x1 = $matches[3];
157  $y1 = $matches[4];
158  // draw a rect around the selection
159  $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"rectangle " .
160  $x0 . "," . $y0 . " " . ($x1) . "," . $y1 . "\" " .
161  "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"rectangle " .
162  $x0 . "," . $y0 . " " . ($x1) . "," . $y1 . "\" ";
163  } elseif ($area["visible"] and strcmp(strtolower($area["shape"]), "circle") == 0) {
164  preg_match("/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area["coords"], $matches);
165  $x = $matches[1];
166  $y = $matches[2];
167  $r = $matches[3];
168  // draw a circle around the selection
169  $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"circle " .
170  $x . "," . $y . " " . ($x+$r) . "," . $y . "\" " .
171  "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"circle " .
172  $x . "," . $y . " " . ($x+$r) . "," . $y . "\" ";
173  } elseif ($area["visible"] and strcmp(strtolower($area["shape"]), "poly") == 0) {
174  $obj = "polygon";
175  // draw a polygon around the selection
176  preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
177  if (count($matches[0]) == 2) {
178  $obj = "line";
179  }
180  $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"$obj ";
181  for ($i = 0; $i < count($matches[0]); $i++) {
182  $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " ";
183  }
184  $convert_cmd .= "\" ";
185  $convert_cmd .= "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"$obj ";
186  preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
187  for ($i = 0; $i < count($matches[0]); $i++) {
188  $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " ";
189  }
190  $convert_cmd .= "\" ";
191  }
192  }
193 
194  $source = ilUtil::escapeShellCmd($this->imagemap_filename);
195  $target = ilUtil::escapeShellCmd($this->preview_filename);
196  $convert_cmd = $source . "[0] " . $convert_cmd . " " . $target;
197  ilUtil::execConvert($convert_cmd);
198  }
$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
$i
Definition: disco.tpl.php:19
$source
Definition: linkback.php:22
+ Here is the call graph for this function:

◆ getAreaCount()

ilImagemapPreview::getAreaCount ( )

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

55  {
56  return count($this->areas);
57  }

◆ getAreaIdent()

ilImagemapPreview::getAreaIdent ( )

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

Referenced by getPreviewFilename().

112  {
113  if (count($this->areas)+count($this->points) > 0) {
114  $arr = array_merge(array_keys($this->areas), array_keys($this->points));
115  sort($arr, SORT_NUMERIC);
116 
117  $inner = join("_", $arr);
118  if (strlen($inner) > 32) {
119  $inner = md5($inner);
120  }
121  return "preview_" . $inner . "_";
122  } else {
123  return "";
124  }
125  }
+ 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 230 of file class.ilImagemapPreview.php.

231  {
232  $map = "<map name=\"$title\"> ";
233  foreach ($this->areas as $area) {
234  $map .= "<area alt=\"" . $area["title"] . "\" title=\"" . $area["title"] . "\" ";
235  $map .= "shape=\"" . $area["shape"] . "\" ";
236  $map .= "coords=\"" . $area["coords"] . "\" ";
237  if ($area["href"]) {
238  $map .= "href=\"" . $area["href"] . "\" ";
239  if ($area["target"]) {
240  $map .= "target=\"" . $area["target"] . "\" ";
241  }
242  $map .= "/>\n";
243  } else {
244  $map .= "nohref />\n";
245  }
246  }
247  $map .= "</map>";
248  return $map;
249  }

◆ getPointCount()

ilImagemapPreview::getPointCount ( )

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

60  {
61  return count($this->points);
62  }

◆ getPreviewFilename()

ilImagemapPreview::getPreviewFilename (   $imagePath,
  $baseFileName 
)

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

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

201  {
202  $filename = $baseFileName;
203  if (count($this->areas)+count($this->points)>0) {
204  $pfile = $this->preview_filename;
205  if (is_file($pfile)) {
206  $ident = $this->getAreaIdent();
207  $previewfile = $imagePath . $ident . $baseFileName;
208  if (@md5_file($previewfile) != @md5_file($pfile)) {
209  if (strlen($ident) > 0) {
210  @copy($pfile, $previewfile);
211  }
212  }
213  @unlink($pfile);
214  if (strlen($pfile) == 0) {
215  ilUtil::sendInfo($this->lng->txt("qpl_imagemap_preview_missing"));
216  } else {
217  $filename = basename($previewfile);
218  }
219  } else {
220  ilUtil::sendInfo($this->lng->txt("qpl_imagemap_preview_missing"));
221  }
222  }
223  return $filename;
224  }
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: