00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 require_once "./classes/class.ilUtil.php";
00025
00037 class ilImagemapPreview
00038 {
00039 var $imagemap_filename;
00040 var $preview_filename;
00041 var $areas;
00042 var $linewidth_outer;
00043 var $linewidth_inner;
00044
00053 function ilImagemapPreview(
00054 $imagemap_filename = "",
00055 $preview_filename = ""
00056 )
00057 {
00058 $this->imagemap_filename = $imagemap_filename;
00059 $this->preview_filename = $preview_filename;
00060 if (!is_file($this->preview_filename))
00061 {
00062 $this->preview_filename = ilUtil::ilTempnam() . ".jpg";
00063 }
00064 $this->areas = array();
00065 $this->linewidth_outer = 4;
00066 $this->linewidth_inner = 2;
00067 }
00068
00069 function addArea(
00070 $shape,
00071 $coords,
00072 $title = "",
00073 $href = "",
00074 $target = "",
00075 $visible = true,
00076 $linecolor = "red",
00077 $bordercolor = "white",
00078 $fillcolor = "\"#FFFFFFC0\""
00079 )
00080 {
00081 array_push($this->areas, array(
00082 "shape" => "$shape",
00083 "coords" => "$coords",
00084 "title" => "$title",
00085 "href" => "$href",
00086 "target" => "$target",
00087 "linecolor" => "$linecolor",
00088 "fillcolor" => "$fillcolor",
00089 "bordercolor" => "$bordercolor",
00090 "visible" => (int)$visible
00091 ));
00092 }
00093
00094 function deleteArea($key, $value)
00095 {
00096 foreach ($this->areas as $areakey => $areavalue)
00097 {
00098 if (strcmp($value, $areavalue[$key]) == 0)
00099 {
00100 unset($this->areas[$areakey]);
00101 }
00102 }
00103 $this->areas = array_values($this->areas);
00104 }
00105
00106 function createPreview()
00107 {
00108 if (!count($this->areas)) return;
00109 $convert_prefix = ilUtil::getConvertCmd() . " -quality 100 ";
00110 foreach ($this->areas as $area)
00111 {
00112 if ($area["visible"] and strcmp(strtolower($area["shape"]), "rect") == 0)
00113 {
00114 preg_match("/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area["coords"], $matches);
00115 $x0 = $matches[1];
00116 $y0 = $matches[2];
00117 $x1 = $matches[3];
00118 $y1 = $matches[4];
00119
00120 $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"rectangle " .
00121 $x0 . "," . $y0 . " " . ($x1) . "," . $y1 . "\" " .
00122 "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"rectangle " .
00123 $x0 . "," . $y0 . " " . ($x1) . "," . $y1 . "\" ";
00124 }
00125 else if ($area["visible"] and strcmp(strtolower($area["shape"]), "circle") == 0)
00126 {
00127 preg_match("/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area["coords"], $matches);
00128 $x = $matches[1];
00129 $y = $matches[2];
00130 $r = $matches[3];
00131
00132 $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"circle " .
00133 $x . "," . $y . " " . ($x+$r) . "," . $y . "\" " .
00134 "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"circle " .
00135 $x . "," . $y . " " . ($x+$r) . "," . $y . "\" ";
00136 }
00137 else if ($area["visible"] and strcmp(strtolower($area["shape"]), "poly") == 0)
00138 {
00139
00140 $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"polygon ";
00141 preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
00142 for ($i = 0; $i < count($matches[0]); $i++)
00143 {
00144 $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " ";
00145 }
00146 $convert_cmd .= "\" ";
00147 $convert_cmd .= "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"polygon ";
00148 preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
00149 for ($i = 0; $i < count($matches[0]); $i++)
00150 {
00151 $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " ";
00152 }
00153 $convert_cmd .= "\" ";
00154 }
00155 }
00156 $convert_cmd = $convert_prefix . $convert_cmd . "$this->imagemap_filename $this->preview_filename";
00157 system($convert_cmd);
00158 }
00159
00160 function getPreviewFilename()
00161 {
00162 return $this->preview_filename;
00163 }
00164
00169 function getImagemap($title)
00170 {
00171 $map = "<map name=\"$title\"> ";
00172 foreach ($this->areas as $area)
00173 {
00174 $map .= "<area alt=\"" . $area["title"] . "\" title=\"" . $area["title"] . "\" ";
00175 $map .= "shape=\"" . $area["shape"] . "\" ";
00176 $map .= "coords=\"" . $area["coords"] . "\" ";
00177 if ($area["href"])
00178 {
00179 $map .= "href=\"" . $area["href"] . "\" ";
00180 if ($area["target"])
00181 {
00182 $map .= "target=\"" . $area["target"] . "\" ";
00183 }
00184 $map .= "/>\n";
00185 }
00186 else
00187 {
00188 $map .= "nohref />\n";
00189 }
00190 }
00191 $map .= "</map>";
00192 return $map;
00193 }
00194
00195 }
00196 ?>