Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Pixels to Points #1364

Closed

Conversation

wilsondealmeida
Copy link

@wilsondealmeida wilsondealmeida commented Oct 22, 2024

Motivation

Convert pixels to points.
Useful when you are working with images.

Example:

1.px
=> 0.75 # points

800.px
=> 600.0 # points

# @param px [Number]
# @return [Number]
def px2pt(px)
px * 72 / 96.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The number "72" comes from the PDF specification. Where does the number "96" come from?

As far as I'm aware the standard DPI seems to be 96 but DPI can be changed by the user.

@pointlessone
Copy link
Member

Thank you for your contribution.

PDF has no concept of a sized pixel as such. So length can not be converted to pixels and vice versa. This conversion is completely a CSS thing (CSS Values and Units Module Level 3, Absolute Lengths). I understand when you might want this but this is outside of PDF so I'd rather keep it outside of Prawn.

I suggest you use a refinement in your application.


I'm closing this for the reason above but feel free to continue discussion and suggest other improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants