Search code examples
imagemagickimagemagick-convert

Image magick convert ignores some images


I am using this command to flatten 3 images in a folder.

for pos1 in 1*.png; do  for pos3 in 3*.png; do  for pos6 in 6*.png; do convert -gravity center $pos1 $pos3 $pos6 -layers flatten  $pos1$pos3$pos6 ;done  ;done ;done

this is how my folder looks:

enter image description here

For some reason, imagemagick ignores the 1*.png images and creates a composition of just $pos3 and $pos6. What could be the reason for this behaviour and how do I fix it? The images i am manipulating are the product of some older image magick manipulation.

UPDATE:

After some more testing it looks like that the error comes from the fact that the input images are the output of come previous convert / composite command (cant remember which one I used). Still, I don't know how to fix this problem.

identify command output (no histogram):

Format: PNG (Portable Network Graphics)
  Mime type: image/png
  Class: DirectClass
  Geometry: 3843x3402+0+0
  Units: Undefined
  Type: TrueColorAlpha
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
    alpha: 1-bit
  Channel statistics:
    Pixels: 13073886
    Red:
      min: 0 (0)
      max: 255 (1)
      mean: 246.072 (0.96499)
      standard deviation: 44.204 (0.173349)
      kurtosis: 23.2206
      skewness: -4.96363
      entropy: 0.0669139
    Green:
      min: 0 (0)
      max: 255 (1)
      mean: 246.072 (0.96499)
      standard deviation: 44.2038 (0.173348)
      kurtosis: 23.2205
      skewness: -4.96362
      entropy: 0.0669169
    Blue:
      min: 0 (0)
      max: 255 (1)
      mean: 246.072 (0.96499)
      standard deviation: 44.2038 (0.173348)
      kurtosis: 23.2207
      skewness: -4.96364
      entropy: 0.066917
    Alpha:
      min: 255 (1)
      max: 255 (1)
      mean: 255 (1)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
      entropy: 0
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 184.554 (0.723742)
      standard deviation: 38.2817 (0.150124)
      kurtosis: 150.659
      skewness: -25.8099
      entropy: 0.050187
  Rendering intent: Perceptual
  Gamma: 0.45455
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Background color: white
  Border color: srgba(223,223,223,1)
  Matte color: grey74
  Transparent color: none
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 3843x3402+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Zip
  Orientation: Undefined
  Properties:
    date:create: 2017-04-05T20:18:59+02:00
    date:modify: 2017-04-05T10:36:08+02:00
    png:bKGD: chunk was found (see Background color, above)
    png:cHRM: chunk was found (see Chromaticity, above)
    png:gAMA: gamma=0.45454544 (See Gamma, above)
    png:IHDR.bit-depth-orig: 8
    png:IHDR.bit_depth: 8
    png:IHDR.color-type-orig: 6
    png:IHDR.color_type: 6 (RGBA)
    png:IHDR.interlace_method: 0 (Not interlaced)
    png:IHDR.width,height: 3843, 3402
    png:sRGB: intent=0 (Perceptual Intent)
    png:text: 2 tEXt/zTXt/iTXt chunks were found
    png:tIME: 2017-04-03T18:20:37Z
    signature: ea0ce8b483b92bda18d999d203a5e1329d48fb63059d6702051b74f7930286fc
  Artifacts:
    filename: /Users/mainuser/Desktop/final/HALFS/to/1_1ND1_1.png
    verbose: true
  Tainted: False
  Filesize: 710KB
  Number pixels: 13.07M
  Pixels per second: 54.47MB
  User time: 0.230u
  Elapsed time: 0:01.240
  Version: ImageMagick 6.9.7-3 Q16 x86_64 2017-01-07 http://www.imagemagick.org

Solution

  • Updated Answer

    As we are having some problems and you can't share your images, let's make some of our own:

    convert -size 600x200 xc:none -fill red -draw "circle 100,100 100,200" -bordercolor black -border 1 1.png
    

    enter image description here

    convert -size 600x200 xc:none -fill lime -draw "circle 300,100 400,100" -bordercolor black -border 1 2.png
    

    enter image description here

    convert -size 600x200 xc:none -fill blue -draw "circle 500,100 600,100" -bordercolor black -border 1 3.png
    

    enter image description here

    Now let's flatten them onto a transparent background:

    convert [123].png -background none -flatten result.png
    

    enter image description here

    Maybe you can create these images and try with your version of ImageMagick.

    Original Answer

    It depends on how your files are in terms of size and transparency, but try this in the middle of your loop:

    convert -gravity center "$pos1" "$pos3" -composite "$pos6" -composite "${pos1}${pos3}${pos6}.png"
    

    This assumes that "$pos1" is the largest file in terms of pixel dimensions.

    Note that you should always double quote shell variables when expanding them in case your filenames happen to have spaces in them.