tags:

views:

749

answers:

2

Dear all, i want to convert my pixel into to the point size, in my project when user resize the text image, then it should be re size according to width using point size??

any one have any idea?

A: 

1 pixel= 0.264583333 mm,
1 mm = 3.779527559 pixel
according to translatorscafe.com
but in reality Pixel is a relative measurement, which depends on your screen resolution. You can't actually convert a relative measurement correctly into a fixed measurement, you can only approximate it. And the correctness of the approximation depends on how accurate your assumptions are, in this case the assumption is 1 pixel = 0.264583333 mm

Assuming for example my case: I have a resolution of 1920 x 1080 pixel (according to windows display settings). Then I have an 18 inch monitor on my laptop. That means 18 inch in the diagonal, and since 1 inch is 25.4 millimeters (according to google), this makes 457.2 mm in the diagonal (according to calc.exe). Assuming furthermore that a pixel is relative to mm equally in length as in width, that means monitor is 1080/1920 th times as heigth as it is with. Using the pythagoran theorem a^2 + b^2 = c^2 = 457.2^2 mm^2 and a is x and b is 1080/1920 x we have (x)^2+ (1080/1920 x)^2 = 457.2^2 mm^2 Solving for x results in 398.4843356 mm (according to Casio Classpad 300)

So if my screen is 1920 pixels in width equaling 398.4843356 mm a pixel for me is 0.20754392479166666666666666666667 mm

So now you can calculate, if I switch down my resolution to 1280 x 768 pixel, the equation becomes: x^2 + (768/1280*x)^2 = 457.2^2 mm^2 x resolves to x=392.0457656 (according to Casio Classpad 300) and thus 1280 pixels correspond to 392.0457656 mm, which makes 1 pixel equal to 0.3062857544 mm.

This is why everything gets bigger (relative to each other) if you switch down the resolution. Measurements are in pixel, but actual size is in mm.

So you see, same screen, but different outcome, but each one is correct. SO you see, pixel = relative to resolution, but not to mm.

Imports Microsoft.VisualBasic



Namespace Units

Public Class UnitConversion

    Public Shared Function mm2Points(ByRef dSomeMillimeters As Double) As System.Web.UI.WebControls.Unit
        ' Point ist eine Maßeinheit, die 1/72 Zoll entspricht.
        ' 1 Zoll = 1 in = 1000 Thou = 1000 mil = 1/12 ft = 1/36 yd = 25,4 mm = 2,54 cm = 0,254 dm = 0,0254 m.
        ' 1 Point = 0.35277777777777777777777777777778 mm
        ' --> 1mm = 2.834645669291338582677165354337 Point

        Return System.Web.UI.WebControls.Unit.Point(dSomeMillimeters * 2.8346456692913384) 'Point
    End Function


    Public Shared Function mm2Pica(ByRef dSomeMillimeters As Double) As System.Web.UI.WebControls.Unit
        'Pica ist eine Maßeinheit, die 12 Points entspricht.
        ' The contemporary computer pica is 1/72nd of the Anglo-Saxon compromise foot of 1959, i.e. 4.23_3mm or 0.166in. Not
        ' 1 Pica = 4.233333333333333333333333333333333 mm
        ' --> 1 mm = 0.23622047244094488188976377952758 Pica
        Return dSomeMillimeters * 0.23622047244094488
    End Function


    Public Shared Function cm2Points(ByRef dSomeCentiMeters As Double) As System.Web.UI.WebControls.Unit
        Return mm2Points(dSomeCentiMeters * 10.0)
    End Function


    Public Shared Function cm2Pica(ByRef dSomeCentiMeters As Double) As System.Web.UI.WebControls.Unit
        Return mm2Pica(dSomeCentiMeters * 10.0)
    End Function

End Class

End Namespace
Quandary
he is asking for php.
metal-gear-solid
@ metal-gear-solid: If he has finished primary school, he sould be able to deduce the PHP code from this...
Quandary
hey i dont and @ metal-gear-solid : your answer is helpful to me really
Chirag
The important bit of this answer is the bit about the ratio between pixels and points being variable. You can't really approximate it, you can only make assumptions. You will come across 96 DPI systems and you will come across 120 DPI systems (among others). That is a *huge* variance. If you are working over the web, don't even try to convert between them. If you are dealing with content for screen then using pixels for images and ems or % for font size. If you are dealing with a print stylesheet, think about pt for everything.
David Dorward
@David Dorward: +1 exactly, and if he wanted to convert it non-the less, he would need the client's screen resolution, which one can get via JavaScript, but JavaScript is clientside, and PHP is serverside, so he at least would need AJAX to do this. Which means, it's impossible to do with PHP alone.
Quandary
The resolution doesn't really matter, its the DPI that counts. I don't think that is available to JS in browsers (and that assumes the system is correctly calibrated in the first place)
David Dorward
A: 

Al final todo se reduce a mm y como dijo Albert Einstein: "Todo es relativo"

Jorge Vargas