question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

location / coordinates of images on canvas

See original GitHub issue

I’m trying to find the x,y,width,height of images on the canvas, similar to the div/span text layer. I would also like a separate image file as well. I’m going to do two things with this for academic articles: scroll to figures after clicking a link and show the images in a separate gallery. In the svg:img, I see there is a url which shows only the image with it’s original size, is there a way to get that url without searching through the svg object? The images in the svg are placed on the page using a series of transforms. Is there a way to get the x,y,width,height without measuring the size of the rendered svg:img?

// get svg which contains img elements
      const opList = await page.getOperatorList()
      let svgGfx = new pdfjsLib.SVGGraphics(page.commonObjs, page.objs);
      svgGfx.embedFonts = true;
      const svg = await svgGfx.getSVG(opList, viewport) // image url in svg:img elements

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
TomasHubelbauercommented, Aug 5, 2019

Basically each paintImageXObject op was preceded by a transform op and that transform op had a corresponding args which were six numbers two last of which were the X and Y coordinates. I think this will be true for many PDFs.

https://github.com/TomasHubelbauer/puppeteer-globus-scraper/blob/master/index.mjs#L63

2reactions
matt-erhartcommented, Jan 26, 2019

I also found this code:

let objs = [];
      for (var i = 0; i < opList.fnArray.length; i++) {
        // paintInlineImageXObject paintImageXObject 
        if (opList.fnArray[i] == pdfjsLib.OPS.paintImageXObject) {
          objs.push(opList.argsArray[i][0]);
        }
      }
const img = await page.objs.get(objs[0]); //width, height, data, kind=2, what is 'kind'?

It can get the Uint8ClampedArray of imagedata but it is divisible by 3 (therefore rgb) rather than 4 (rgba: what canvas wants). Adding the alpha channel in a loop seems slow, is there a faster way? Seems like this ‘search the ops list’ approach might have the img x,y,width,height, but still not sure how to get at that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get coordinates x y of image in a canvas - Stack Overflow
I want to get the coordinates x,y of my picture inside this canvas even if I zoom on it or drag it. javascript...
Read more >
HTML Image Map in Canvas
Discover an amazing HTML image mapping technique! ... All the coordinates are based on the upper left corner of the map, which is...
Read more >
HTML Canvas Coordinates - W3Schools
Canvas Coordinates. The HTML canvas is a two-dimensional grid. · Coordinates Example. Mouse over the rectangle below to see its x and y...
Read more >
HTML image map in Canvas - YouTube
Convert your uploaded image into an interactive map of hotspots. This is a fantastic way to create dynamic content in your Canvas course...
Read more >
Use the Go-to Coordinate tool—ArcGIS Excalibur
A location pin centers and pans in the Map Focus Panel. If the Image Focus Panel is open, the location pin will center...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found