Image map image preview creator. More...
Public Member Functions | |
ilImagemapPreview ($imagemap_filename="") | |
ilImagemapPreview constructor | |
getAreaCount () | |
addArea ($index, $shape, $coords, $title="", $href="", $target="", $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 | |
Data Fields | |
$imagemap_filename | |
$preview_filename | |
$areas | |
$linewidth_outer | |
$linewidth_inner |
Image map image preview creator.
Takes an image and imagemap areas and creates a preview image containing the imagemap areas.
Definition at line 35 of file class.ilImagemapPreview.php.
ilImagemapPreview::addArea | ( | $ | index, | |
$ | shape, | |||
$ | coords, | |||
$ | title = "" , |
|||
$ | href = "" , |
|||
$ | target = "" , |
|||
$ | visible = true , |
|||
$ | linecolor = "red" , |
|||
$ | bordercolor = "white" , |
|||
$ | fillcolor = "\"#FFFFFFA0\"" | |||
) |
Definition at line 75 of file class.ilImagemapPreview.php.
{ if (ini_get("safe_mode")) { if ((strpos($fillcolor, "#") !== false) ||Â (strpos($fillcolor, "rgb") !== false)) { $fillcolor = str_replace("\"", "", $fillcolor); } } $this->areas[$index] = array( "shape" => "$shape", "coords" => "$coords", "title" => "$title", "href" => "$href", "target" => "$target", "linecolor" => "$linecolor", "fillcolor" => "$fillcolor", "bordercolor" => "$bordercolor", "visible" => (int)$visible ); }
ilImagemapPreview::createPreview | ( | ) |
Definition at line 122 of file class.ilImagemapPreview.php.
References $x, and ilUtil::getConvertCmd().
{ if (!count($this->areas)) return; include_once "./classes/class.ilUtil.php"; $convert_prefix = ilUtil::getConvertCmd() . " -quality 100 "; foreach ($this->areas as $area) { if ($area["visible"] and strcmp(strtolower($area["shape"]), "rect") == 0) { preg_match("/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area["coords"], $matches); $x0 = $matches[1]; $y0 = $matches[2]; $x1 = $matches[3]; $y1 = $matches[4]; // draw a rect around the selection $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"rectangle " . $x0 . "," . $y0 . " " . ($x1) . "," . $y1 . "\" " . "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"rectangle " . $x0 . "," . $y0 . " " . ($x1) . "," . $y1 . "\" "; } else if ($area["visible"] and strcmp(strtolower($area["shape"]), "circle") == 0) { preg_match("/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/", $area["coords"], $matches); $x = $matches[1]; $y = $matches[2]; $r = $matches[3]; // draw a circle around the selection $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"circle " . $x . "," . $y . " " . ($x+$r) . "," . $y . "\" " . "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"circle " . $x . "," . $y . " " . ($x+$r) . "," . $y . "\" "; } else if ($area["visible"] and strcmp(strtolower($area["shape"]), "poly") == 0) { // draw a polygon around the selection $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"polygon "; preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER); for ($i = 0; $i < count($matches[0]); $i++) { $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " "; } $convert_cmd .= "\" "; $convert_cmd .= "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"polygon "; preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER); for ($i = 0; $i < count($matches[0]); $i++) { $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " "; } $convert_cmd .= "\" "; } } $convert_cmd = $convert_prefix . $convert_cmd . escapeshellcmd(str_replace(" ", "\ ", $this->imagemap_filename)) ." " . escapeshellcmd($this->preview_filename); system($convert_cmd); }
ilImagemapPreview::getAreaCount | ( | ) |
Definition at line 70 of file class.ilImagemapPreview.php.
{
return count($this->areas);
}
ilImagemapPreview::getAreaIdent | ( | ) |
Definition at line 108 of file class.ilImagemapPreview.php.
Referenced by getPreviewFilename().
{ if (count($this->areas) > 0) { $arr = array_keys($this->areas); sort($arr, SORT_NUMERIC); return "preview_" . join("_", $arr) . "_"; } else { return ""; } }
ilImagemapPreview::getImagemap | ( | $ | title | ) |
get imagemap html code note: html code should be placed in template files
Definition at line 216 of file class.ilImagemapPreview.php.
{ $map = "<map name=\"$title\"> "; foreach ($this->areas as $area) { $map .= "<area alt=\"" . $area["title"] . "\" title=\"" . $area["title"] . "\" "; $map .= "shape=\"" . $area["shape"] . "\" "; $map .= "coords=\"" . $area["coords"] . "\" "; if ($area["href"]) { $map .= "href=\"" . $area["href"] . "\" "; if ($area["target"]) { $map .= "target=\"" . $area["target"] . "\" "; } $map .= "/>\n"; } else { $map .= "nohref />\n"; } } $map .= "</map>"; return $map; }
ilImagemapPreview::getPreviewFilename | ( | $ | imagePath, | |
$ | baseFileName | |||
) |
Definition at line 177 of file class.ilImagemapPreview.php.
References getAreaIdent(), and sendInfo().
{ $filename = $baseFileName; if (count($this->areas)) { $pfile = $this->preview_filename; if (is_file($pfile)) { $ident = $this->getAreaIdent(); $previewfile = $imagePath . $ident . $baseFileName; if (@md5_file($previewfile) != @md5_file($pfile)) { if (strlen($ident) > 0) { @copy($pfile, $previewfile); } } @unlink($pfile); if (strlen($pfile) == 0) { ilUtil::sendInfo($this->lng->txt("qpl_imagemap_preview_missing")); } else { $filename = basename($previewfile); } } else { ilUtil::sendInfo($this->lng->txt("qpl_imagemap_preview_missing")); } } return $filename; }
ilImagemapPreview::ilImagemapPreview | ( | $ | imagemap_filename = "" |
) |
ilImagemapPreview constructor
Creates an instance of the ilImagemapPreview class
integer | $id The database id of a image map question object public |
Definition at line 51 of file class.ilImagemapPreview.php.
References $imagemap_filename, $preview_filename, and ilUtil::ilTempnam().
{ $this->imagemap_filename = $imagemap_filename; $this->preview_filename = $preview_filename; if (!@is_file($this->preview_filename)) { $extension = ".jpg"; if (preg_match("/.*\.(png|jpg|gif|jpeg)$/", $this->imagemap_filename, $matches)) { $extension = "." . $matches[1]; } include_once "./classes/class.ilUtil.php"; $this->preview_filename = ilUtil::ilTempnam() . $extension; } $this->areas = array(); $this->linewidth_outer = 4; $this->linewidth_inner = 2; }
ilImagemapPreview::$areas |
Definition at line 39 of file class.ilImagemapPreview.php.
ilImagemapPreview::$imagemap_filename |
Definition at line 37 of file class.ilImagemapPreview.php.
Referenced by ilImagemapPreview().
ilImagemapPreview::$linewidth_inner |
Definition at line 41 of file class.ilImagemapPreview.php.
ilImagemapPreview::$linewidth_outer |
Definition at line 40 of file class.ilImagemapPreview.php.
ilImagemapPreview::$preview_filename |
Definition at line 38 of file class.ilImagemapPreview.php.
Referenced by ilImagemapPreview().