0

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
sanjihan
  • 5,592
  • 11
  • 54
  • 119

2 Answers2

1

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.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Images are around 3500x 3500 in size, all are the same size, and mostly transparent. I tried the suggestion above, but the result is the same. it just won't overlap them... – sanjihan Apr 05 '17 at 18:27
  • order: $pos3 $pos6 $pos1 -> output is just $pos1 – sanjihan Apr 05 '17 at 18:40
  • order: $pos3 $pos1 $pos6 -> output is just $pos1 and $pos6 – sanjihan Apr 05 '17 at 18:42
  • order: $pos6 $pos1 $pos3-> output is just $pos3 and so on. I manage to get 2 images to overlap, but never 3 – sanjihan Apr 05 '17 at 18:42
  • Maybe you have paging info in your images.... try adding `+repage` immediately after each input image name. – Mark Setchell Apr 05 '17 at 19:09
  • can't share, it is a production asset. tried +repage, same result. How do I check image magick version? – sanjihan Apr 05 '17 at 19:12
  • `identify -version` will tell you the version number - 7.0.5 is current. – Mark Setchell Apr 05 '17 at 19:15
  • jp, i am a version behind :) i added the output of identify -verbose command – sanjihan Apr 05 '17 at 19:17
  • `identify 1_1ND1_3.png` will tell you if the image has paging info - if the 4th field has a different number from the 3rd. – Mark Setchell Apr 05 '17 at 19:17
  • I think I don't have paging. output: 1_1ND1_3.png PNG 3843x3402 3843x3402+0+0 8-bit sRGB 710KB 0.000u 0:00.000. I updated to the latest version, the error persist. I guess I will be switching to some other command line image processing tool – sanjihan Apr 05 '17 at 19:20
  • I have added some example images of my own - please look again. – Mark Setchell Apr 05 '17 at 19:30
  • Mmmm... I have to suspect your images then - but I cannot see them! – Mark Setchell Apr 05 '17 at 20:21
  • Your images are not transparent. The alpha value in the output of `identify -verbose` is 1. – Mark Setchell Apr 05 '17 at 21:06
  • my god... aaaaaaa! that explains everything. i can only max overlap 2, because 2 are opaque and "erase" everything below. amazing. The original files are transparent, but one of the commands I used to prepare images made background white. Thank you so much. I've been trying to solve this from 9am (it's 11pm right now). And a note to my self: lower the flux settings. It makes white looking like grey (macs use grey for transparent images :D i guess I am just looking excuses for my stupidity) – sanjihan Apr 05 '17 at 21:22
  • Yes, the Quicklook and Preview on a Mac are a pain because they don't show transparency properly. You can use this to do a chessboard effect like Photoshop... `composite -compose Dst_Over -tile pattern:checkerboard yourImage.png sensible.jpg` – Mark Setchell Apr 05 '17 at 21:33
0

This is not the answer to the original question but I found it because I had the same problem that images were just ignored when using convert.

My solution was allocate higher ressources in resources.xml as described in this solution.

Maybe this is useful to someone at some point.

AlbertRapp
  • 408
  • 2
  • 9