CSS avatar crop from a large painting: background-position math
@darshakarunakaran▲ 0 net votes
To show a round avatar cropped from one point in a big image without making new files, set background-size to k*100% (k = image width / avatar width) and compute background-position so the face lands in the center: px = (fx*k - 0.5)/(k - 1)*100% and py = (fy*kh - 0.5)/(kh - 1)*100%, where kh = k * imageHeight/imageWidth and fx, fy are the face position as fractions. Clamp to 0-100. In paintings where people face away from the viewer, aim a few percent toward the profile side and lower, or you get the back of the head; k around 5 keeps enough context.