/** * Overlay image * * Parameter array: * 'x': int X-point of overlayed image * 'y': int Y-point of overlayed image * 'filename': string The filename of the image to overlay * 'width': int [optional] The width of the overlayed image (resizing if possible) * 'height': int [optional] The height of the overlayed image (resizing if possible) * 'alignment': array [optional] Alignment */ function image($params) { $x = $this->_getX($params['x']); $y = $this->_getY($params['y']); $filename = $params['filename']; $width = isset($params['width']) ? $params['width'] : false; $height = isset($params['height']) ? $params['height'] : false; $alignment = isset($params['alignment']) ? $params['alignment'] : false; if (substr($filename, -4) == '.png') { $type = 'png'; } elseif (substr($filename, -4) == '.jpg') { $type = 'jpeg'; } $image = ps_open_image_file($this->_ps, $type, realpath($filename), ''); $width_ = ps_get_value($this->_ps, 'imagewidth', $image); $height_ = ps_get_value($this->_ps, 'imageheight', $image); $outputWidth = $width !== false ? $width : $width_; $outputHeight = $height !== false ? $height : $height_; if (!is_array($alignment)) { $alignment = array('vertical' => 'top', 'horizontal' => 'left'); } if (!isset($alignment['vertical'])) { $alignment['vertical'] = 'top'; } if (!isset($alignment['horizontal'])) { $alignment['horizontal'] = 'left'; } if ($alignment['horizontal'] == 'right') { $x -= $outputWidth; } elseif ($alignment['horizontal'] == 'center') { $x -= $outputWidth / 2; } if ($alignment['vertical'] == 'top') { $y += $outputHeight; } elseif ($alignment['vertical'] == 'center') { $y += $outputHeight / 2; } if ($width === false && $height === false) { $scale = 1; } else { $scale = max($height / $height_, $width / $width_); } ps_place_image($this->_ps, $image, $x, $y, $scale); ps_close_image($this->_ps, $image); parent::image($params); }
ps_stroke($ps); ps_setcolor($ps, "both", "rgb", 1.0, 0.0, 0.0, 0.0); ps_moveto($ps, 50, 10); ps_curveto($ps, 50, 10, 110, 40, 90, 90); ps_curveto($ps, 90, 90, 30, 90, 80, 70); ps_curveto($ps, 80, 70, 100, 10, 50, 10); ps_fill($ps); end_example_box($ps); } if (isset($_REQUEST['box8']) && $_REQUEST['box8'] == "true") { if ($x > 3) { $y -= 150; $x = 0; } begin_example_box($ps, LEFT_BORDER + (EXAMPLE_BOX_WIDTH + 30) * $x++, $y, "EPS-Image", $psfont); $psimage = ps_open_image_file($ps, "eps", "picture.eps", NULL, 0); ps_place_image($ps, $psimage, 10, 10, 0.3); ps_close_image($ps, $psimage); end_example_box($ps); } if (isset($_REQUEST['box9']) && $_REQUEST['box9'] == "true") { if ($x > 3) { $y -= 150; $x = 0; } begin_example_box($ps, LEFT_BORDER + (EXAMPLE_BOX_WIDTH + 30) * $x++, $y, "Path (1)", $psfont); ps_moveto($ps, 10, 10); ps_lineto($ps, 50, 50); ps_moveto($ps, 20, 10); ps_lineto($ps, 60, 50); ps_circle($ps, 60, 60, 20);
$psfont = ps_findfont($ps, "Helvetica", "", 0); ps_setfont($ps, $psfont, 12.0); $x = 0; $y = 625; begin_example_box($ps, LEFT_BORDER + (EXAMPLE_BOX_WIDTH + 30) * $x++, $y, "Gif image", $psfont); $psimage = ps_open_image_file($ps, "gif", "debian.gif", NULL, 0); ps_place_image($ps, $psimage, 25, 10, 2.0); end_example_box($ps); begin_example_box($ps, LEFT_BORDER + (EXAMPLE_BOX_WIDTH + 30) * $x++, $y, "Gif image with transparency", $psfont); $psimage = ps_open_image_file($ps, "gif", "debian-transparent.gif", NULL, 0); ps_place_image($ps, $psimage, 25, 10, 2.0); end_example_box($ps); begin_example_box($ps, LEFT_BORDER + (EXAMPLE_BOX_WIDTH + 30) * $x++, $y, "Gif image interlaced", $psfont); $psimage = ps_open_image_file($ps, "gif", "interlaced.gif", NULL, 0); ps_place_image($ps, $psimage, 10, 10, 0.65); end_example_box($ps); $x = 0; $y = 405; begin_example_box($ps, LEFT_BORDER + (EXAMPLE_BOX_WIDTH + 30) * $x++, $y, "Tiff image", $psfont); $psimage = ps_open_image_file($ps, "tiff", "debian.tiff", NULL, 0); ps_place_image($ps, $psimage, 25, 10, 2.0); end_example_box($ps); $x = 0; $y = 185; begin_example_box($ps, LEFT_BORDER + (EXAMPLE_BOX_WIDTH + 30) * $x++, $y, "Bmp image", $psfont); $psimage = ps_open_image_file($ps, "bmp", "debian.bmp", NULL, 0); ps_place_image($ps, $psimage, 25, 10, 2.0); end_example_box($ps); ps_end_page($ps); ps_close($ps); ps_delete($ps);