ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilImagemapPreview Class Reference

Image map image preview creator. More...

+ Collaboration diagram for ilImagemapPreview:

Public Member Functions

 ilImagemapPreview ($imagemap_filename="")
 ilImagemapPreview constructor
 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

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:
class.ilImagemapPreview.php 33364 2012-02-27 10:58:08Z jluetzen

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

Member Function Documentation

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

Definition at line 86 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::addPoint (   $index,
  $coords,
  $visible = true,
  $linecolor = "red",
  $bordercolor = "white",
  $fillcolor = "#FFFFFFA0" 
)

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

{
$this->points[$index] = array(
"coords" => "$coords",
"linecolor" => '"' . $linecolor . '"',
"fillcolor" => '"' . $fillcolor . '"',
"bordercolor" => '"' . $bordercolor . '"',
"visible" => (int)$visible
);
}
ilImagemapPreview::createPreview ( )

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

References ilUtil\escapeShellCmd(), and ilUtil\execConvert().

{
if (count($this->areas)+count($this->points)==0) return;
include_once "./Services/Utilities/classes/class.ilUtil.php";
$convert_cmd = "-quality 100 ";
foreach ($this->points as $point)
{
if ($point["visible"])
{
preg_match("/(\d+)\s*,\s*(\d+)/", $point["coords"], $matches);
$x = $matches[1];
$y = $matches[2];
$r = 6;
// draw a circle at the point
$convert_cmd .= "-stroke " . $point["bordercolor"] . " -fill " . $point["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"line " .
($x-$r) . "," . ($y-$r) . " " . ($x+$r) . "," . ($y+$r) . "\" " .
"-stroke " . $point["bordercolor"] . " -fill " . $point["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"line " .
($x+$r) . "," . ($y-$r) . " " . ($x-$r) . "," . ($y+$r) . "\" " .
"-stroke " . $point["linecolor"] . " -fill " . $point["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"line " .
($x-$r) . "," . ($y-$r) . " " . ($x+$r) . "," . ($y+$r) . "\" " .
"-stroke " . $point["linecolor"] . " -fill " . $point["fillcolor"] . " -strokewidth $this->linewidth_inner -draw \"line " .
($x+$r) . "," . ($y-$r) . " " . ($x-$r) . "," . ($y+$r) . "\" ";
}
}
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)
{
$obj = "polygon";
// draw a polygon around the selection
preg_match_all("/(\d+)\s*,\s*(\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
if (count($matches[0]) == 2) $obj = "line";
$convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth $this->linewidth_outer -draw \"$obj ";
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 \"$obj ";
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 .= "\" ";
}
}
$source = ilUtil::escapeShellCmd($this->imagemap_filename);
$target = ilUtil::escapeShellCmd($this->preview_filename);
$convert_cmd = $source . "[0] " . $convert_cmd." ".$target;
ilUtil::execConvert($convert_cmd);
}

+ Here is the call graph for this function:

ilImagemapPreview::getAreaCount ( )

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

{
return count($this->areas);
}
ilImagemapPreview::getAreaIdent ( )

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

Referenced by getPreviewFilename().

{
if (count($this->areas)+count($this->points) > 0)
{
$arr = array_merge(array_keys($this->areas), array_keys($this->points));
sort($arr, SORT_NUMERIC);
$inner = join("_", $arr);
if (strlen($inner) > 32) {
$inner = md5($inner);
}
return "preview_" . $inner . "_";
}
else
{
return "";
}
}

+ Here is the caller graph for this function:

ilImagemapPreview::getImagemap (   $title)

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

Definition at line 274 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::getPointCount ( )

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

{
return count($this->points);
}
ilImagemapPreview::getPreviewFilename (   $imagePath,
  $baseFileName 
)

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

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

{
$filename = $baseFileName;
if (count($this->areas)+count($this->points)>0)
{
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;
}

+ Here is the call graph for this function:

ilImagemapPreview::ilImagemapPreview (   $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 54 of file class.ilImagemapPreview.php.

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

{
global $lng;
$this->lng =& $lng;
$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 "./Services/Utilities/classes/class.ilUtil.php";
$this->preview_filename = ilUtil::ilTempnam() . $extension;
}
$this->areas = array();
$this->points = array();
$this->linewidth_outer = 4;
$this->linewidth_inner = 2;
}

+ Here is the call graph for this function:

Field Documentation

ilImagemapPreview::$areas

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

ilImagemapPreview::$imagemap_filename

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

Referenced by ilImagemapPreview().

ilImagemapPreview::$linewidth_inner

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

ilImagemapPreview::$linewidth_outer

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

ilImagemapPreview::$lng

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

Referenced by ilImagemapPreview().

ilImagemapPreview::$points

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

ilImagemapPreview::$preview_filename

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

Referenced by getPreviewFilename(), and ilImagemapPreview().


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