Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fit an image to a fixed size box using pythonMagick in python

try:
    original = PythonMagick.Blob(data)
    image = PythonMagick.Image(original)
except Exception as e:
    raise errors.UnknownFileFormat()

medium = PythonMagick.Blob()
small = PythonMagick.Blob()
large = PythonMagick.Blob()
largesize = "128X128"
mediumsize = "64X64"
smallsize = "48X48"

image.scale(largesize)
image.write(large)
image.scale(mediumsize)
image.write(medium)
image.scale(smallsize)
image.write(small)

Now, what I need is to create a base image of each of the sizes and overlay these images on top of it. So that when I show display in an img tag with fixed width and height, the browser does not stretch them. The lack of documentation is aggravating me.

like image 653
Abhi Avatar asked Nov 14 '22 21:11

Abhi


1 Answers

You can probably achieve what you are trying to do in CSS by background-size:cover or background-size:contain and background-position:...;. May be more complicated if trying to do other things.

like image 107
ninjagecko Avatar answered May 02 '23 13:05

ninjagecko