bayd3 / block-camera

a camera for screen-shotting d3js blocks
3 stars 0 forks source link

Respect Custom Height from .block #2

Open curran opened 6 years ago

curran commented 6 years ago

I notice the viewport height is set to 500, but some bl.ocks have a custom height set in the .block file. Ideally the thumbnails would have the same aspect ratio as the original bl.ock with custom height.

I wrote some code that may be useful for you here:

export const computeImageDimensions = ({ actual, desired }) =>
  actual.width / actual.height < desired.width / desired.height
    ?
      {
        width: desired.width,
        height: Math.round(actual.height / actual.width * desired.width)
      }
    :
      {
        width: Math.round(actual.width / actual.height * desired.height),
        height: desired.height
      };

I'd be happy to release this as a separate package if that would be useful.

micahstubbs commented 6 years ago

interesting. I had not considered this case yet 🤔

thanks for making the issue!

micahstubbs commented 6 years ago

I think I want to find a new name for this third category of block thumbnail images.

in the strict sense, I think of

preview as 960x500 thumbnail as 230x120

ie, these are two labels for fixed dimensions, large and small in the same 48:25 aspect ratio

and perhaps we could also a native or author-intent image size, which could be 960x block.config.height

again 🤔

micahstubbs commented 6 years ago

I could also image a fourth conventional thumbnail size, which would be fullPage, optionally resized to some target width.

micahstubbs commented 6 years ago

(this is different from my immediate use-case of showing nice 230x120 thumbnails for a search results page. that said, it sounds like it is something that would be useful to support for other use cases 😄 )