我正在使用此命令压缩文件夹中的3张图像。
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
这是我文件夹的外观:
出于某种原因,imagemagick会忽略1*.png
张图片并创建仅$pos3
和$pos6
的合成。可能是这种行为的原因,我该如何解决?我正在操纵的图像是一些较老的图像魔法处理的产物。
更新:
经过一些更多测试后,看起来错误来自于输入图像是先前转换/复合命令的输出这一事实(无法记住我使用的是哪一个)。不过,我不知道如何解决这个问题。
识别命令输出(无直方图):
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
答案 0 :(得分:1)
更新了答案
由于我们遇到了一些问题并且您无法分享您的图片,请让我们自己制作一些:
convert -size 600x200 xc:none -fill red -draw "circle 100,100 100,200" -bordercolor black -border 1 1.png
convert -size 600x200 xc:none -fill lime -draw "circle 300,100 400,100" -bordercolor black -border 1 2.png
convert -size 600x200 xc:none -fill blue -draw "circle 500,100 600,100" -bordercolor black -border 1 3.png
现在让它们展平到透明背景上:
convert [123].png -background none -flatten result.png
也许您可以创建这些图片并尝试使用您的ImageMagick版本。
原始答案
这取决于您的文件在大小和透明度方面的方式,但请在循环中间尝试:
convert -gravity center "$pos1" "$pos3" -composite "$pos6" -composite "${pos1}${pos3}${pos6}.png"
这假定" $ pos1"是像素尺寸方面最大的文件。
请注意,在扩展它们时,应始终双引用shell变量,以防文件名恰好包含空格。