Created
March 10, 2017 13:06
-
-
Save benosteen/4a9527ded8b77e33bdd9ab9d2cad25f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 'doc' is ALTO XML, parsed into an etree xml obj. | |
def get_illustration_coords(doc, component="PrintSpace"): | |
page = doc.find("Layout/Page") | |
illustrations = doc.findall('Layout/Page/{0}/ComposedBlock[@TYPE="Illustration"]/GraphicalElement'.format(component)) | |
pageh, pagew = int(page.attrib['HEIGHT']), int(page.attrib['WIDTH']) | |
images = [] | |
for img in illustrations: | |
x,y = map(int, [img.attrib['HPOS'], img.attrib['VPOS']]) | |
h,w = map(int, [img.attrib['HEIGHT'], img.attrib['WIDTH']]) | |
images.append([x,y,w,h]) | |
return (pagew, pageh), images |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment