CSS scale down image to fit in containing div, without specifing original size

You can use a background image to accomplish this; From MDN – Background Size: Contain: This keyword specifies that the background image should be scaled to be as large as possible while ensuring both its dimensions are less than or equal to the corresponding dimensions of the background positioning area. Demo CSS: #im { position: … Read more

PIL how to scale text size in relation to the size of the image

You could just increment the font size until you find a fit. font.getsize() is the function that tells you how large the rendered text is. from PIL import ImageFont, ImageDraw, Image image = Image.open(‘hsvwheel.png’) draw = ImageDraw.Draw(image) txt = “Hello World” fontsize = 1 # starting font size # portion of image width you want … Read more

Is it possible to adjust a font’s vertical scaling using CSS?

The transform property can be used to scale text. It’s for blocks, so you’ll need to also add display: inline-block in order to use it on HTML elements like <a>, <span>, <em>, <kbd>, etc. body { font-family: “HelveticaNeue-Medium”, sans-serif; font-size: 12px; } a.vertical-scaling { display: inline-block; transform: scale(1, 1.5); /* Safari and Chrome */ -webkit-transform: … Read more

Scale image keeping its aspect ratio in background drawable

It is impossible to achieve manipulating background attribute within xml-files only. There are two options: You cut/scale the bitmap programmatically with Bitmap.createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter) and set it as some View‘s background. You use ImageView instead of background placing it as the first layout’s element and specify android:scaleType attribute for it: … Read more

Chrome, Safari ignoring max-width in table

Max-width applies to block elements. <table> is neither block nor inline. Ambiguous enough? haha. You can use display:block; max-width:1000px and forget about width:100%. Chrome and Safari follow the rules! Edit May 2017: please note, this comment was made 7 years ago (in 2010!). I suspect browsers have changed a bunch over the years (I wouldn’t … Read more

How to scale down a UIImage and make it crispy / sharp at the same time instead of blurry?

Merely using imageWithCGImage is not sufficient. It will scale, but the result will be blurry and suboptimal whether scaling up or down. If you want to get the aliasing right and get rid of the “jaggies” you need something like this: http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/. My working test code looks something like this, which is Trevor’s solution with … Read more