首先,我不是图形程序员,我可能不知道我想做什么的正确术语。我知道自己想做什么,但我还没知道怎么做。我将尝试描述我想要的内容,但请记住,我可能会错误地使用术语。也许有一种更好的方式来做我想做的事情,而不是我认为我需要做的事情。
我的主要目标是:我有一张大小为250000字节的图片,我希望缩小文件大小。
请注意,原始图片是全亮度,但我使用了gimp(可能不正确)使其具有褪色外观。我认为它现在有一个" alpha通道"具有一些不透明度百分比值。所以我认为图片在rgb通道中存储为全亮度,并且还有另一个alpha通道描述" fadedness"的图片。图像应淡入白色" - 它将被放置在白色背景上并且上面会有深色文字 - 但我不认为我已经在图像中存储了最后一点信息(
)。所以我在这里尝试如何到达那里:如果我只是指定rgb通道中褪色图片的实际像素值并取消alpha通道,我认为图片可能会更小。此外,总体上应该有更少的颜色,我可以使用彩色地图,使图片更小。褪色的图片褪色得足以使文字在书写时清晰可辨 - 即它已经褪色 - 因此应该比全亮度版本的颜色少得多。
但是,我不知道如何做到这一点,或者在文档中寻找什么。我已经尝试了一些"压缩"程序和我得到的最佳压缩率约为2.5%。显然我没有找到合适的位置,因为我认为应该压缩到比这更小的位置。
这是imagemagick"识别-verbose"输出:
bjb@rhino:~/work/mojatatu/admin/2015/web/foo/img/work$ identify -verbose ../orig/joanrobins-penguins-snow-banner-faded.png Image: ../orig/joanrobins-penguins-snow-banner-faded.png Format: PNG (Portable Network Graphics) Class: DirectClass Geometry: 799x152+0+0 Resolution: 137.8x137.8 Print size: 5.79826x1.10305 Units: PixelsPerCentimeter Type: TrueColorAlpha Endianess: Undefined Colorspace: sRGB Depth: 8-bit Channel depth: red: 8-bit green: 8-bit blue: 8-bit alpha: 8-bit Channel statistics: Red: min: 0 (0) max: 255 (1) mean: 145.053 (0.568837) standard deviation: 51.0466 (0.200183) kurtosis: 0.897068 skewness: -1.18367 Green: min: 0 (0) max: 253 (0.992157) mean: 152.236 (0.597003) standard deviation: 53.6199 (0.210274) kurtosis: 0.941151 skewness: -1.2307 Blue: min: 0 (0) max: 251 (0.984314) mean: 164.608 (0.645521) standard deviation: 56.552 (0.221772) kurtosis: 1.13143 skewness: -1.37866 Alpha: min: 84 (0.329412) max: 84 (0.329412) mean: 84 (0.329412) standard deviation: 0 (0) kurtosis: 0 skewness: 0 Image statistics: Overall: min: 0 (0) max: 255 (1) mean: 158.224 (0.620487) standard deviation: 46.5805 (0.182669) kurtosis: 2.94443 skewness: -1.70687 Rendering intent: Perceptual Gamma: 0.454545 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) Interlace: None Background color: white Border color: srgba(223,223,223,1) Matte color: grey74 Transparent color: none Compose: Over Page geometry: 799x152+0+0 Dispose: Undefined Iterations: 0 Compression: Zip Orientation: Undefined Properties: date:create: 2015-03-21T19:32:58-04:00 date:modify: 2015-03-21T19:32:58-04: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 : 8 png:IHDR.color_type : 6 (RGBA) png:IHDR.interlace_method: 0 (Not interlaced) png:IHDR.width,height : 799, 152 png:pHYs : x_res=13780, y_res=13780, units=1 png:sRGB : intent=0 (See Rendering intent) signature: 6ceec80b4c3c05a631de400d74928ca4cb86bd9f304676ecd4a475b874a71cfc Artifacts: filename: ../orig/joanrobins-penguins-snow-banner-faded.png verbose: true Tainted: False Filesize: 248KB Number pixels: 121K Pixels per second: 0B User time: 0.000u Elapsed time: 0:01.000 Version: ImageMagick 6.7.7-10 2014-03-08 Q16 http://www.imagemagick.org
我查看了一些ImageMagick文档并尝试了以下大多数工具(我还必须缩小.jpg并发现jpegoptim运行良好)。
Setting up advancecomp (1.15-1) ... advpng -z4 file.png. didn't see any compression
Setting up jpegoptim (1.2.3-2+b2) ... two thumbs up - easy and effective
Setting up optipng (0.6.4-1) ...
Setting up pngcrush (1.7.9-1) ...
Setting up pngnq (1.0-2) ...
Setting up pngquant (1.0-4.1) ...
Setting up trimage (1.0.5-1) ...
imagemagic convert
convert
-clut (apply a color lookup table to the image)
-hald-clut
-unique-colors
-quantize colorspace <- reduce colors in this colorspace
-posterize levels <- reduce the image to a limited number of color levels
-modulate value <- vary the brightness, saturation, and hue
-layers method optimize or compare image layers
-fuzz distance colors within this distance are considered equal
-depth value image depth
-alpha remove
on, activate, off, deactivate, set, opaque, copy", transparent, extract, background, or shape the alpha channel
-background white
- colors value preferred number of colors in the image
- colorspace type set image colorspace
我还尝试将图片转换为jpg然后回到png,希望它可以做我想要的但是它将全亮度版本保存为jpg并再次作为png保存,可能会丢失alpha频道信息。
pngcrush -brute
尝试超过100种压缩技术并选择最佳压缩技术,即提供约2.5%最佳压缩效果的技术。但是,鉴于我完全愿意丢失信息(对保持原始亮度信息不感兴趣),这张照片肯定会被压缩得更多吗?
答案 0 :(得分:3)
要使用您创建的Alpha通道,使用png bKGD块中的白色背景构建透明图像,您可以
convert rgba.png -flatten -alpha off rgb-flattened.png
然后优化压缩并删除一些辅助块 ImageMagick插入,
pngcrush -reduce -brute -rem alla rgb-flattened.png rgb.png
请注意,选项“-alpha off”和“-flatten”的顺序很重要。 如果先将“-alpha”设置为“-alpha”,则不会在展平过程中使用Alpha通道,最终会得到原始未填充图像。
编辑:要进一步优化,请使用-colors 255将图像从RGBA-PNG缩小为索引-PNG:
convert rgba.png -flatten -alpha off -colors 255 indexed-flattened.png
pngcrush -reduce -brute -rem alla indexed-flattened.png indexed.png
答案 1 :(得分:1)
不太确定你真正想要的是什么,但也许这会让你朝着正确的方向前进。如果你想要一个&#34; 褪色的外观&#34;,你通常可以通过降低图像的对比度来实现这一点 - 这样黑色就会变得比黑色更灰,而白色变得更灰而不是白色,或通过降低饱和度来降低色彩强度,使照片不那么鲜艳或更趋于黑白。
因此,您可以执行以下操作以丢弃Alpha通道(透明度)并降低对比度并减少图像中的颜色数量。文件大小从250kB下降到62kB - 但它可能不是你想要的......
convert yourPengy.png -alpha off +level 65%,95% -colors 256 myPengy.png
或者这可能更接近你想要的,饱和度降低到80%,达到62kB
convert yourPengy.png -alpha off -modulate 100,80 +level 55%,95% -colors 256 myPengy.png