librelist archives

« back to archive

How to resize with extent

How to resize with extent

From:
Timur Tabi
Date:
2013-11-24 @ 19:55
I have a bash shell script that manipulates images with ImageMagick,
and I'm trying to convert it into a Python script that uses Wand.
Unfortunately, I'm not very good at Python, so a lot of things about
Wand confuse me.

I'm trying to convert this bash function into python+wand:

function resize()
{
     convert $1 -resize 300x420 -extent 300x460 $2
}

I get that 'resize' is handle with img.size(), but what about the
extent?  Is there a an easy way to handle that?

I'm guessing that I'm going to have to create a blank 300x460 image
and then merge my resized image onto that one.  I can probably figure
that out.

Re: [wand] How to resize with extent

From:
Hong Minhee
Date:
2013-11-25 @ 03:07
Hi Timur,

I think resize() function you pasted could be directly ported to Python
using Wand:

  from wand.image import Image

  def resize(src, dst):
      with Image(filename=src) as src_image:
          src_image.resize(300, 420)
          with Image(width=300, height=460) as dst_image:
              dst_image.composite(src_image, 0, 0)
              dst_image.save(filename=dst)


Thanks,
Minhee


On Mon, Nov 25, 2013 at 4:55 AM, Timur Tabi <timur@tabi.org> wrote:

> I have a bash shell script that manipulates images with ImageMagick,
> and I'm trying to convert it into a Python script that uses Wand.
> Unfortunately, I'm not very good at Python, so a lot of things about
> Wand confuse me.
>
> I'm trying to convert this bash function into python+wand:
>
> function resize()
> {
>      convert $1 -resize 300x420 -extent 300x460 $2
> }
>
> I get that 'resize' is handle with img.size(), but what about the
> extent?  Is there a an easy way to handle that?
>
> I'm guessing that I'm going to have to create a blank 300x460 image
> and then merge my resized image onto that one.  I can probably figure
> that out.
>