contradicting resize using Windows/Linux/python/console

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mleo
Posts: 11
Joined: 2016-07-05T06:07:14-07:00
Authentication code: 1151

contradicting resize using Windows/Linux/python/console

Post by mleo »

Hi,

using same call for modifier -resize und Windows and Linux convert results in different sizes.

Windows version: ImageMagick 6.9.0-0
Linux version: ImageMagick 6.8.9-9

in.jpg = https://postimg.org/image/r6z743nub/

convert call:

Code: Select all

convert -trim -resize 512x512^> in.jpg out.jpg # Windows
convert -trim -resize 512x512\> in.jpg out.jpg # Linux
Both calls create images of size 512x177

Now I use the following python script convert.py to call the commands:

Code: Select all

import os, subprocess, sys

def mycall(call_list):
  if os.name == 'posix':
    print(' '.join(call_list), '###')
    subprocess.call(call_list)
  elif os.name == 'nt':
    if call_list[0] == 'convert':
      call_list[0] = os.path.normpath('C:\\Program Files\\ImageMagick-6.9.0-Q16\\convert.exe')
      assert os.path.isfile(call_list[0])
    print(' '.join(call_list), '###')
    subprocess.call(call_list, shell=False)
  else:
    assert False

def _escape(text):
  if os.name == 'posix':
    return text.replace('>', r'\>')
  if os.name == 'nt':
    return text.replace('>', '^>')
  else:
    assert False

src = sys.argv[1]
trg = sys.argv[2]

call_list = ['convert', '-trim', '-resize', _escape('512x512>'), src, trg]
mycall(call_list)
calling python (version 3.5) via

Code: Select all

python convert.py in.jpg out.jpg
I get different sizes:
  • under Linux 512x177 and
  • under Windows 1484x512.
Before calling the command from python I print it, the debugging outprint is:

Code: Select all

C:\Program Files\ImageMagick-6.9.0-Q16\convert.exe -trim -resize 512x512^> in.jpg out.jpg ###
so this is called from python under windows but it results in 1484x512.

What is the mistake? I cannot fetch it.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: contradicting resize using Windows/Linux/python/console

Post by fmw42 »

I do not know the answer to your question, but proper IM 6 syntax would have the input image read right after convert and the -trim following the input. Does that make any difference?

Since the image is jpg, the border color will never be constant. You might add a bit of -fuzz XX% to allow for non-constant background.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: contradicting resize using Windows/Linux/python/console

Post by snibgo »

You have dumped the contents of call_list, which Python has built. It looks okay. But I don't know exactly what gets passed to ImageMagick.

I suggest you insert "-debug All" and examine the first part of the debug output, eg:

Code: Select all

f:\web\im>%IM%convert -debug All rose: -resize 512x512^> r.png

2016-08-31T01:06:18+01:00 0:00.000 0.000u 6.9.5 Configure 

convert.exe[9456]: utility.c/ExpandFilenames/940/Configure
  Command line: c:\im\ImageMagick-6.9.5-3-Q16\convert {-debug} {All} {rose:} {-resize} {512x512>} {r.png}
The argument to {-resize} should be {512x512>}.
snibgo's IM pages: im.snibgo.com
mleo
Posts: 11
Joined: 2016-07-05T06:07:14-07:00
Authentication code: 1151

Re: contradicting resize using Windows/Linux/python/console

Post by mleo »

Thank you. Both propositions look okay but have no effect. The strange thing is that convert works as a minimum and not as a maximum dimension resizer when called by python. I cannot imagine that this could be an mistake of python but I will ask there in a forum.
mleo
Posts: 11
Joined: 2016-07-05T06:07:14-07:00
Authentication code: 1151

Re: contradicting resize using Windows/Linux/python/console

Post by mleo »

Solution: Should be called without escaper so _x_> instead of _x_^> or _x_\>.
Post Reply