Hi, I'd like to crop a bitmap image. How? This is my code for image inclusion: ------- \directlua{ image = img.scan{filename="hacker.jpg"} tex.box[0] = node.hpack(img.node(image)) } \box0 ------- bbox{...} seems to work only with PDF images. Patrick
On 7/1/2013 1:51 PM, Patrick Gundlach wrote:
Hi,
I'd like to crop a bitmap image. How? This is my code for image inclusion:
------- \directlua{ image = img.scan{filename="hacker.jpg"} tex.box[0] = node.hpack(img.node(image)) }
\box0 -------
bbox{...} seems to work only with PDF images.
use the pdf clip operator i.e. set a path with 'l' and 'm' and then apply the operator 'W n' Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Am 01.07.2013 um 14:32 schrieb Hans Hagen
On 7/1/2013 1:51 PM, Patrick Gundlach wrote:
Hi,
I'd like to crop a bitmap image. How? This is my code for image inclusion:
------- \directlua{ image = img.scan{filename="hacker.jpg"} tex.box[0] = node.hpack(img.node(image)) }
\box0 -------
bbox{...} seems to work only with PDF images.
use the pdf clip operator i.e. set a path with 'l' and 'm' and then apply the operator 'W n'
where? I mean, what is a good place to put the pdf instructions? Patrick
On 7/1/2013 2:59 PM, Patrick Gundlach wrote:
Am 01.07.2013 um 14:32 schrieb Hans Hagen
: On 7/1/2013 1:51 PM, Patrick Gundlach wrote:
Hi,
I'd like to crop a bitmap image. How? This is my code for image inclusion:
------- \directlua{ image = img.scan{filename="hacker.jpg"} tex.box[0] = node.hpack(img.node(image)) }
\box0 -------
bbox{...} seems to work only with PDF images.
use the pdf clip operator i.e. set a path with 'l' and 'm' and then apply the operator 'W n'
where?
I mean, what is a good place to put the pdf instructions?
best pack the img in a box and then put some qQ around it with the clip at the end (the usual experimenting with origin), so basically something compatible to \pdfliteral {q clip spec} \pdfximage{...} \pdfliteral {Q} ending up in something q 0 w 0 0 m 29.99991 0 l 29.99991 39.9999 l 0 39.9999 l W n BT /F1 11.955168 Tf 1 0 0 1 -10 51.8346 Tm [<00730073>]TJ ET Q this is a clip path: x,y=10bp,20bp w,h=30bp,40bp (using text XX instead of image) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hello Hans,
best pack the img in a box and then put some qQ around it with the clip at the end (the usual experimenting with origin), so basically something compatible to
\pdfliteral {q clip spec} \pdfximage{...} \pdfliteral {Q}
ending up in something
that works fine, thank you very much! This is my test code now: ----------------------- \directlua{ a=node.new("whatsit","pdf_literal") b=node.new("whatsit","pdf_literal") a.data = "q 0 w 20 20 m 140 20 l 140 160 l 20 160 l W n " b.data = "Q" image = img.scan{filename="cow.pdf"} i = img.node(image) node.insert_after(a,a,i) node.insert_after(a,i,b) head = node.hpack(a) tex.box[0] = head } \box0 \bye ----------------------- I wonder how it compares to the slightly different approach pdflatex uses (pdftex.def?). If I see it correctly the graphicx package creates an xobject/form from the bitmap and changes the bounding box there. Thanks again! Patrick
On 7/1/2013 9:10 PM, Patrick Gundlach wrote:
Hello Hans,
best pack the img in a box and then put some qQ around it with the clip at the end (the usual experimenting with origin), so basically something compatible to
\pdfliteral {q clip spec} \pdfximage{...} \pdfliteral {Q}
ending up in something
that works fine, thank you very much! This is my test code now:
----------------------- \directlua{ a=node.new("whatsit","pdf_literal") b=node.new("whatsit","pdf_literal") a.data = "q 0 w 20 20 m 140 20 l 140 160 l 20 160 l W n " b.data = "Q" image = img.scan{filename="cow.pdf"} i = img.node(image) node.insert_after(a,a,i) node.insert_after(a,i,b) head = node.hpack(a) tex.box[0] = head }
\box0
\bye
looks ok to me
-----------------------
I wonder how it compares to the slightly different approach pdflatex uses (pdftex.def?). If I see it correctly the graphicx package creates an xobject/form from the bitmap and changes the bounding box there.
i don't know (never looked into it) but maybe it's wrapped twice then, once as image (form) and as box (form) or maybe they add a crop box in the resources that then overloads the mediabox but i guess that the clip is okay (i used that method for years) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
participants (2)
-
Hans Hagen
-
Patrick Gundlach