简体   繁体   English

在各种移动设备上将网页上的图像缩放到1厘米宽

[英]scaling an image on webpage to 1cm width across various mobile devices

I am trying to scale an image on a mobile web page (packaged via cordova for Android/iOS) so it always has a known width in centimeters. 我正在尝试在移动网页上缩放图像(通过Cordova打包为Android / iOS),因此它始终具有以厘米为单位的已知宽度。 Regardless of the screen resolution / size - I need the image to have a known width in centimeters. 不管屏幕分辨率/大小如何-我都需要图像具有以厘米为单位的已知宽度。 If I would be doing this 'the native way' I would check the screen ppi (points per inch) and then adjust image width in pixels accordingly. 如果我要执行这种“本机方式”,我将检查屏幕的ppi(每英寸点数),然后相应地调整以像素为单位的图像宽度。

I tried various solutions from stackoverflow but failed to find a solution. 我尝试了stackoverflow的各种解决方案,但未能找到解决方案。

Is developing a cordova plugin that would cover that on each platform separately is the only solution or this can be done via some javascript (or cordova) code. 正在开发一个cordova插件,它将分别覆盖每个平台上的唯一解决方案,或者可以通过一些javascript(或cordova)代码来完成。

You are not limited to pixels in CSS these days, check out http://www.w3.org/Style/Examples/007/units.en.html for reference, so aside from px, em, pt you can just use cm for centimeters, or in for inch. 如今,您不仅限于CSS中的像素,请访问http://www.w3.org/Style/Examples/007/units.en.html作为参考,因此除了px,em和pt之外,您还可以使用cm厘米或英寸。

SO, to answer your question, you can just do 所以,要回答您的问题,您可以

<img src="someimg.png" style="width:1cm;" />

EDIT: when I open your testpage, on my system, it works like a charm. 编辑:当我在系统上打开您的测试页时,它就像一个超级按钮。 But yeah, in that case you will probably need to do some extra work, maybe detecting the DPI with a method like https://stackoverflow.com/questions/9292156/how-to-detect-the-screen-dpi-using-php-or-javascript can bridge the gap. 但是,是的,在这种情况下,您可能需要做一些额外的工作,也许可以使用https://stackoverflow.com/questions/9292156/how-to-detect-the-screen-dpi-using- php-or-javascript可以缩小差距。

Good luck! 祝好运!

bovako 博瓦科

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM