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
How to Round Images Without Soft Masks? #1028
Comments
Anyone? |
I'm afraid, you have to calculate mask size yourself. You'd need to find out image dimensions beforehand using some other library and calculate scaled size also you'd need to position the mask properly to align with the image. |
Here's a quick and rough code example that accomplishes an image crop in PrawnPdf: bounding_box([bounds.width * 0.5, cursor], width: 200, height: 113) do
image_width = 200
image_height = 113
crop_size = 20
save_graphics_state do
soft_mask do
fill_color 0, 0, 0, 0
fill_rectangle [crop_size, image_height - crop_size], image_width - crop_size * 2, image_height - crop_size * 2
end
image "#{IMAGES_PATH}/cat.jpg", at: [bounds.left, bounds.top], width: image_width, height: image_height
end
stroke_bounds
end |
After rereading the original issue here are some pointers:
I've added a small clarification to documentation where the mask applies. Otherwise it seem that it works as expected. |
I'm trying to create a pdf document in which on each page there are some bounding boxes containing images that must fit either by width or height, and have their corners rounded.
That sounds simple, but I'm having a problem. The images I'm adding should be aligned at the right of the bounding boxes, and I'm using the "fit" parameter so the image is scaled accordingly (the problem is I don't know the size or aspect ratio of the image beforehand).
I know I can round an image using a soft mask with a filled rectangle (#000000) plus a filled rounded rectangle (#FFFFFF) on top of it, that should do the trick. However, since I don't know the image.scaled_width and image.scaled_height until I put it on the bounding_box, I can't create the mask before adding the image, and it seems the image is not affected by the soft if it's added later on.
How do I round the corners of an image in this scenario?
The text was updated successfully, but these errors were encountered: