0

So I want to splice an image into two, for which I wrote this code.

from wand.image import Image
from wand.display import display
with Image(filename="test.png") as im :
  im.trim(color=None,fuzz=0)
  x,y = im.size
  xh,yh = int(x/2),int(y/2)
  print(x,y,xh,yh)
  im1 = im[0:xh,0:y]
  print(im1.size)
  display(im1)

The size of image is (1156,242) and hence the spliced image should be (578,242), but it's (553,235) instead. Anyone knows why? Here is the test image.

Navdeep Rana
  • 111
  • 1
  • 7

1 Answers1

1

This is the effect of using wand.image.Image.trim. A simple "repage" is all that's needed.

from wand.image import Image

with Image(filename="test.png") as im :
  im.trim(color=None,fuzz=0)
  im.reset_coords()  # <= Same as `-repage'
  x,y = im.size
  xh,yh = int(x/2),int(y/2)
  print(x,y,xh,yh)
  im1 = im[0:xh,0:y]
  print(im1.size)
  display(im1)

I don't have the doc links handy at the moment, but a quick search for ImageMagick's -repage command line option should help describe the process.

emcconville
  • 23,800
  • 4
  • 50
  • 66