xmlgraphics-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremias Maerki <...@jeremias-maerki.ch>
Subject Re: How do I merge 2 EPS images?
Date Tue, 14 Dec 2010 07:45:34 GMT
comments inline...

On 14.12.2010 00:15:27 olivierk wrote:
> 
> 
> 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?

I think so, yes.

> 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);

That's why I talked about PS knowledge. It is, unfortunately, not enough
to just create a PSGenerator instance. You have to create a proper
wrapper for the whole content, especially when the goal is to get an EPS
file. After all, you're missing the procset for EPS handling which is
why your result is no valid EPS file.

Take a look at examples/java/java2d/ps/EPSExample1.java for an example
on how to create a proper EPS file. You can copy that example and call
renderEPS() in place of Java2D operations.

I've quickly made a copy of that and adjusted it to how I would do it.
The result is a valid EPS document which displays the embedded EPS files,
but just not in the right position, yet. You'll have to experiment and
keep in mind that PostScript's coordinate system grows from bottom up
with increasing Y coordinate (and not top to bottom). I've attached the
result.

Finally, some EPS files have a binary wrapper around them which
needs to be removed for embedding. Fully loading the EPS using the image
loader framework lets you extract the text contents as shown in the
attached example.


> //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.
> 



HTH
Jeremias Maerki


Mime
View raw message