xmlgraphics-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From olivierk <okite...@gmail.com>
Subject Re: How do I merge 2 EPS images?
Date Mon, 13 Dec 2010 23:15:27 GMT


Jeremias Maerki-2 wrote:
> 
> And the result should be another EPS?
> 
yes.

Jeremias Maerki-2 wrote:
> 
> the result will be a plain PostScript document, not an EPS file
> 
Can the resulting document be opened with Illustrator or Inkscape?

Jeremias Maerki-2 wrote:
> 
> You don't say what kind of approach you've used so far
> 
Essentially, I open the two EPS images as input streams then I call
PSImageUtils.renderEPS for each of them using the same PSGenerator.

here is the code:

ImageManager imageManager = new ImageManager(new DefaultImageContext());
ImageSessionContext sessionContext = new DefaultImageSessionContext(
		  imageManager.getImageContext(), null);
		  
//image info for the center and border images
ImageInfo centerInfo = imageManager.getImageInfo("center_image.eps",
sessionContext);
ImageInfo borderInfo = imageManager.getImageInfo("border_image.eps",
sessionContext);

//input streams
InputStream centerStream = new BufferedInputStream(new
FileInputStream("center_image.eps"));
InputStream borderStream = new BufferedInputStream(new
FileInputStream("border_image.eps"));
OutputStream result = new BufferedOutputStream(new
FileOutputStream("result.eps"));

//border image and center image width and height
int borderW = borderInfo.getSize().getWidthMpt() / 1000;
int borderH = borderInfo.getSize().getHeightMpt() / 1000;

int centerW = centerInfo.getSize().getWidthMpt() / 1000;
int centerH = centerInfo.getSize().getHeightMpt() / 1000;

//the viewport and bounding box dimensions are equal to the border image
width and height
//because the border image is bigger than the center image
Rectangle viewport = 
	new Rectangle(0, 0, borderW, borderH);
Rectangle bbox = 
	new Rectangle(0, 0, borderW, borderH);
	
PSGenerator gen = new PSGenerator(result);

//I first render the background image
//note: even when I try to render the border image only, the output file is
still not a valid EPS image

PSImageUtils.renderEPS(borderStream, "", viewport, bbox, gen);

//new bounding box with the center image dimensions
//(I believe the viewport should stay the same, I'm not sure)
//(borderW - centerW) / 2 <--- this is what I came up with to center the
image,
//I used this formula when I worked with other image formats

bbox  = new Rectangle( (borderW - centerW) / 2, (borderH - centerH) / 2,
centerW, centerW);
PSImageUtils.renderEPS(centerStream, "", viewport, bbox, gen);

-- 
View this message in context: http://old.nabble.com/How-do-I-merge-2-EPS-images--tp30448446p30450090.html
Sent from the Xml Graphics - General mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: general-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: general-help@xmlgraphics.apache.org


Mime
View raw message