/** * Loads an image from file * * @param string $image filename * * @return bool|PEAR_Error TRUE or a PEAR_Error object on error * * @access public */ function load($image) { $this->free(); $this->image = $image; $result = $this->_get_image_details($image); if (PEAR::isError($result)) { return $result; } if (!$this->supportsType($this->type, 'r')) { return PEAR::raiseError('Image type not supported for input', IMAGE_TRANSFORM_ERROR_UNSUPPORTED); } $this->surface = cairo_image_surface_create_from_png($this->image); if (cairo_surface_status($this->surface) != CAIRO_STATUS_SUCCESS) { $this->surface = null; return PEAR::raiseError('Error while loading image file.', IMAGE_TRANSFORM_ERROR_IO); } return true; }
/** * 画像を合成 * * 画像ファイル(PNG)を合成します。 * * @param string $file ファイル名 * @param int $x X座標 * @param int $y Y座標 * @param float $alpha アルファブレンディング(0..1) * * @return void */ public function addImage($file, $x = 0, $y = 0, $alpha = 1.0) { $file = $this->loadRemoteFile($file); $surfce = cairo_image_surface_create_from_png($file); cairo_set_source_surface($this->image, $surfce, $x, $y); cairo_paint_with_alpha($this->image, $alpha); }
/** * Draw an image * * The image will be inlined in the SVG document using data URL scheme. For * this the mime type and base64 encoded file content will be merged to * URL. * * @param mixed $file Image file * @param ezcGraphCoordinate $position Top left position * @param mixed $width Width of image in destination image * @param mixed $height Height of image in destination image * @return void */ public function drawImage($file, ezcGraphCoordinate $position, $width, $height) { $this->initiliazeSurface(); // Ensure given bitmap is a PNG image $data = getimagesize($file); if ($data[2] !== IMAGETYPE_PNG) { throw new Exception('Cairo only has support for PNGs.'); } // Create new surface from given bitmap $imageSurface = cairo_image_surface_create_from_png($file); // Create pattern from source image to be able to transform it $pattern = cairo_pattern_create_for_surface($imageSurface); // Scale pattern to defined dimensions and move it to its destination position $matrix = cairo_matrix_multiply($move = cairo_matrix_create_translate(-$position->x, -$position->y), $scale = cairo_matrix_create_scale($data[0] / $width, $data[1] / $height)); cairo_pattern_set_matrix($pattern, $matrix); // Merge surfaces cairo_set_source($this->context, $pattern); cairo_rectangle($this->context, $position->x, $position->y, $width, $height); cairo_fill($this->context); }