how to get smooth resize?

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?".
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

how to get smooth resize?

Post by linjuming »

orignal btn.png
Image

description:
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to get smooth resize?

Post by fmw42 »

try including the alpha channel in your resize

convert image -channel rgba -resize .... result
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

Re: how to get smooth resize?

Post by linjuming »

the same result
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to get smooth resize?

Post by fmw42 »

Also try a different -filter option with -resize

see http://www.imagemagick.org/Usage/resize/

or try -distort SRT

see http://www.imagemagick.org/Usage/distorts/#srt


Otherwise, you may have to "feather" your alpha channel separately.

see
http://www.imagemagick.org/Usage/antialiasing/
http://www.imagemagick.org/Usage/masking/#difference
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: how to get smooth resize?

Post by anthony »

The problem looks like it is your PNG display program not displaying semi-transparent colors,
but only boolean transparency (such as for BMP and GIF images.

Try removing the transparency from the image, replacing it with some color (matching background)
http://www.imagemagick.org/Usage/masking/#remove

These are your only solutions, though the GIF semi-transparency handling goes into some methods
of mixing edge anti-alias colors with boolean transparency for use on patterned or light/dark/grey backgrounds
http://www.imagemagick.org/Usage/formats/#bgnd


Also as you are generating multiple images look at
Writing an Image, Multiple Time
http://www.imagemagick.org/Usage/files/#write
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

Re: how to get smooth resize?

Post by linjuming »

Point Hermite Cubic
Box Gaussian Catrom
Triangle Quadratic Mitchell


Lanczos Hamming Parzen
Blackman Kaiser Welsh
Hanning Bartlett Bohman

i test all filter ,the result are all not good.
ps ,the png is save form photoshop , and the descriptsiotn png is cut from ie6 ,show it has blue background.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to get smooth resize?

Post by fmw42 »

My tests look fine on IM 6.7.3.0 Q16 Mac OSX Tiger

The image under the alpha channel is not too smooth, but the alpha channel is smooth.

convert btn.png -resize 28x28^ btn28.png
Image


convert btn.png -resize 36x36^ btn36.png
Image


convert btn.png -resize 52x52^ btn52.png
Image


Perhaps try upgrading IM and libpng. Anthony may be right that your alpha channel is not being kept as 8-bit, but is getting converted to binary.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: how to get smooth resize?

Post by anthony »

fmw42 wrote:Perhaps try upgrading IM and libpng. Anthony may be right that your alpha channel is not being kept as 8-bit, but is getting converted to binary.
Actually I said that the application displaying the image is probably not displaying the alpha channel properly! :-)

I have a feeling that some of the smaller PNG images are being saved using an 8-bit PNG palette with full semi-transparency capability. This is something that was only recently added to the PNG coder (thanks Glenn). Only happens when the actual color count (including semi-transparency) is less than 256.

Palette PNG's are typically limited to boolean transparency only (IM itself limits it to boolean transparency (like GIF) if PNG8 format is requested), so it may be that your display application thinks that all palette PNG images only has boolean transparency, and is thus displaying them incorrectly.

One solution to 'fix' the PNG, just for the display application, is to use PNG32 format, or one of the many PNG coder settings to ensure a palette sub-format is not used.
http://www.imagemagick.org/Usage/formats/#png_write
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

Re: how to get smooth resize?

Post by linjuming »

Image

Image

Image

Image

Seems png32 is best.
Thank you !
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to get smooth resize?

Post by fmw42 »

In principle, it should not matter if PNG32 or PNG8 with transparency, if you are using the latest version of IM. My test above worked fine without specifying PNG32: and maintained your pseudocolor transparent png format.

You never say what version of IM you are using? Nor what version of libpng.

Note that the PNG developer has made many changes and improvements to the PNG functionality over quite a number of releases. First consideration when using PNG is to be sure you are using the latest version of IM.
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

Re: how to get smooth resize?

Post by linjuming »

i used
ImageMagick-6.7.0-9-Q16-windows-dll.exe
before.now i update to
ImageMagick-6.7.3-1-Q16-windows-dll.exe
but still the same result with old version.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to get smooth resize?

Post by fmw42 »

Must be a windows issue as Unix and Mac do not seem to have that problem. Or perhaps it is your libpng that needs upgrading.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: how to get smooth resize?

Post by anthony »

Earilier versions of IM would have output the image as PNG32. It is only recent IM's that handle semi-transparency palatte (indexed) PNG images.

I doubt your IM is going wrong, your PNG images are probably correct.

It is more than likely it is only your PNG display program that is mis-handling index PNG images. the screen shot says PHP, and I know that most PHP image processing is done using the "gd" library, which is very ancient and very likely to be miss handling indexed PNG with semi-transparent colors. A mode that was only later added to PNG sub-image format.

You are only giving use a screen shot of the 'displayed' image, not the actual problem image, as such it is impossible for us to say for certain that the images generated is correct or not. Can you publish the actual generated images?

Otherwise you can check the actual image sub-format using identify -verbose


For example....

Code: Select all

convert btn-1.png -resize x20^ little.png
identify -verbose little.png | grep Type:
  Type: PaletteMatte
Which showed that MY version of IM did generate a indexed or palette PNG image, just as I suspected!
The image is correct and displays correctly without edge aliasing effects.

I really think it is your display program (written in PHP) that is at fault not IM.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

Re: how to get smooth resize?

Post by linjuming »

Image: little.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 54x20+0+0
Resolution: 72x72
Print size: 0.75x0.277778
Units: Undefined
Type: PaletteMatte
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
alpha: 8-bit
Channel statistics:
Red:
min: 0 (0)
max: 93 (0.364706)
mean: 24.7565 (0.0970842)
standard deviation: 10.199 (0.039996)
kurtosis: 3.84442
skewness: 1.31031
Green:
min: 0 (0)
max: 185 (0.72549)
mean: 102.177 (0.400694)
standard deviation: 44.2577 (0.17356)
kurtosis: -1.00124
skewness: 0.205439
Blue:
min: 0 (0)
max: 255 (1)
mean: 207.85 (0.815098)
standard deviation: 43.5392 (0.170742)
kurtosis: 8.16684
skewness: -2.65481
Alpha:
min: 0 (0)
max: 255 (1)
mean: 239 (0.937255)
standard deviation: 52.3219 (0.205184)
kurtosis: 11.9866
skewness: 3.54869
Image statistics:
Overall:
min: 0 (0)
max: 255 (1)
mean: 87.6958 (0.343905)
standard deviation: 40.9146 (0.160449)
kurtosis: 33.9294
skewness: 5.79701
Alpha: rgba(65,65,205,0) #4141CD00
Colors: 131
Histogram:
16: ( 0, 0, 0, 0) #00000000 none
1: ( 4, 24, 36, 6) #04182406 rgba(4,24,36,0.0235294)
1: ( 6, 30, 53, 36) #061E3524 rgba(6,30,53,0.141176)
1: ( 8, 40, 81, 71) #08285147 rgba(8,40,81,0.278431)
1: ( 8,180,255, 0) #08B4FF00 rgba(8,180,255,0)
1: ( 9, 42, 87,105) #092A5769 rgba(9,42,87,0.411765)
1: ( 10, 44, 94,139) #0A2C5E8B rgba(10,44,94,0.545098)
1: ( 10, 45, 96,146) #0A2D6092 rgba(10,45,96,0.572549)
44: ( 10, 45, 97,153) #0A2D6199 rgba(10,45,97,0.6)
1: ( 12, 49,102, 57) #0C316639 rgba(12,49,102,0.223529)
1: ( 13, 53, 96, 15) #0D35600F rgba(13,53,96,0.0588235)
1: ( 13, 53,114, 95) #0D35725F rgba(13,53,114,0.372549)
1: ( 14, 52,134,194) #0E3486C2 rgba(14,52,134,0.760784)
1: ( 15, 54,147,222) #0F3693DE rgba(15,54,147,0.870588)
1: ( 15, 56,144,178) #0F3890B2 rgba(15,56,144,0.698039)
1: ( 16, 54,124, 0) #10367C00 rgba(16,54,124,0)
1: ( 16, 54,164,241) #1036A4F1 rgba(16,54,164,0.945098)
1: ( 16, 55,175,252) #1037AFFC rgba(16,55,175,0.988235)
1: ( 16, 57,147,211) #103993D3 rgba(16,57,147,0.827451)
1: ( 16, 58,122, 66) #103A7A42 rgba(16,58,122,0.258824)
1: ( 17, 55,177,255) #1137B1 rgba(17,55,177,1)
43: ( 17, 55,179,255) #1137B3 rgba(17,55,179,1)
1: ( 17, 55,180,255) #1137B4 rgba(17,55,180,1)
1: ( 17, 59,158,253) #113B9EFD rgba(17,59,158,0.992157)
1: ( 17, 60,170,242) #113CAAF2 rgba(17,60,170,0.94902)
1: ( 18, 54, 66, 2) #12364202 rgba(18,54,66,0.00784314)
1: ( 18, 58,187,255) #123ABB rgba(18,58,187,1)
1: ( 18, 58,191,255) #123ABF rgba(18,58,191,1)
47: ( 18, 58,198,255) #123AC6 rgba(18,58,198,1)
48: ( 18, 61,199,255) #123DC7 rgba(18,61,199,1)
1: ( 18, 61,200,255) #123DC8 rgba(18,61,200,1)
1: ( 19, 61,144,146) #133D9092 rgba(19,61,144,0.572549)
1: ( 19, 62,162,255) #133EA2 rgba(19,62,162,1)
1: ( 19, 64,190,255) #1340BE rgba(19,64,190,1)
48: ( 19, 64,201,255) #1340C9 rgba(19,64,201,1)
1: ( 19, 64,202,255) #1340CA rgba(19,64,202,1)
1: ( 19, 68,202,255) #1344CA rgba(19,68,202,1)
48: ( 19, 68,203,255) #1344CB rgba(19,68,203,1)
1: ( 19, 68,204,255) #1344CC rgba(19,68,204,1)
50: ( 19, 72,206,255) #1348CE rgba(19,72,206,1)
49: ( 19, 76,208,255) #134CD0 rgba(19,76,208,1)
1: ( 19, 76,209,255) #134CD1 rgba(19,76,209,1)
1: ( 20, 58,102, 0) #143A6600 rgba(20,58,102,0)
1: ( 20, 65,167,255) #1441A7 rgba(20,65,167,1)
1: ( 20, 65,168,215) #1441A8D7 rgba(20,65,168,0.843137)
1: ( 20, 70,189,252) #1446BDFC rgba(20,70,189,0.988235)
1: ( 20, 75,204,255) #144BCC rgba(20,75,204,1)
51: ( 20, 80,211,255) #1450D3 rgba(20,80,211,1)
1: ( 21, 60,124, 36) #153C7C24 rgba(21,60,124,0.141176)
50: ( 21, 88,215,255) #1558D7 rgba(21,88,215,1)
1: ( 21, 88,216,255) #1558D8 rgba(21,88,216,1)
1: ( 22, 68,171,255) #1644AB rgba(22,68,171,1)
1: ( 23, 72,176,255) #1748B0 rgba(23,72,176,1)
1: ( 23, 77,189,236) #174DBDEC rgba(23,77,189,0.92549)
1: ( 23, 86,208,255) #1756D0 rgba(23,86,208,1)
49: ( 23,102,221,255) #1766DD rgba(23,102,221,1)
1: ( 23,102,222,255) #1766DE rgba(23,102,222,1)
1: ( 23,103,222,255) #1767DE rgba(23,103,222,1)
1: ( 24, 65,147,103) #18419367 rgba(24,65,147,0.403922)
1: ( 24, 70,168,183) #1846A8B7 rgba(24,70,168,0.717647)
1: ( 25, 75,181,255) #194BB5 rgba(25,75,181,1)
1: ( 25,103,222,255) #1967DE rgba(25,103,222,1)
49: ( 25,115,227,255) #1973E3 rgba(25,115,227,1)
2: ( 25,116,227,255) #1974E3 rgba(25,116,227,1)
1: ( 26, 28, 0, 1) #1A1C0001 rgba(26,28,0,0.00392157)
1: ( 27, 45, 52, 0) #1B2D3400 rgba(27,45,52,0)
49: ( 27,125,230,255) #1B7DE6 rgba(27,125,230,1)
1: ( 27,125,231,255) #1B7DE7 rgba(27,125,231,1)
1: ( 27,126,232,255) #1B7EE8 rgba(27,126,232,1)
2: ( 27,135,234,255) #1B87EA rgba(27,135,234,1)
1: ( 28, 63,125, 15) #1C3F7D0F rgba(28,63,125,0.0588235)
1: ( 28, 80,187,255) #1C50BB rgba(28,80,187,1)
48: ( 28,134,233,255) #1C86E9 rgba(28,134,233,1)
1: ( 28,144,237,255) #1C90ED rgba(28,144,237,1)
48: ( 29,144,236,255) #1D90EC rgba(29,144,236,1)
1: ( 29,144,237,255) #1D90ED rgba(29,144,237,1)
48: ( 29,153,239,255) #1D99EF rgba(29,153,239,1)
1: ( 29,154,239,255) #1D9AEF rgba(29,154,239,1)
1: ( 30, 69,152, 76) #1E45984C rgba(30,69,152,0.298039)
1: ( 30, 89,194,255) #1E59C2 rgba(30,89,194,1)
1: ( 30,111,223,249) #1E6FDFF9 rgba(30,111,223,0.976471)
1: ( 31, 79,178,169) #1F4FB2A9 rgba(31,79,178,0.662745)
47: ( 31,163,241,255) #1FA3F1 rgba(31,163,241,1)
2: ( 31,164,242,255) #1FA4F2 rgba(31,164,242,1)
1: ( 32,130,232,255) #2082E8 rgba(32,130,232,1)
1: ( 32,152,240,255) #2098F0 rgba(32,152,240,1)
46: ( 32,171,243,255) #20ABF3 rgba(32,171,243,1)
1: ( 32,172,243,255) #20ACF3 rgba(32,172,243,1)
1: ( 33, 90,198,212) #215AC6D4 rgba(33,90,198,0.831373)
1: ( 33, 96,200,255) #2160C8 rgba(33,96,200,1)
2: ( 33,173,245,255) #21ADF5 rgba(33,173,245,1)
1: ( 35,102,206,255) #2366CE rgba(35,102,206,1)
44: ( 35,184,246,255) #23B8F6 rgba(35,184,246,1)
1: ( 35,185,247,255) #23B9F7 rgba(35,185,247,1)
1: ( 36,185,248,255) #24B9F8 rgba(36,185,248,1)
1: ( 37,108,211,255) #256CD3 rgba(37,108,211,1)
1: ( 37,108,216,215) #256CD8D7 rgba(37,108,216,0.843137)
1: ( 38, 87,188,125) #2657BC7D rgba(38,87,188,0.490196)
1: ( 38,129,229,239) #2681E5EF rgba(38,129,229,0.937255)
1: ( 38,182,248,255) #26B6F8 rgba(38,182,248,1)
1: ( 39,114,215,255) #2772D7 rgba(39,114,215,1)
1: ( 39,150,238,254) #2796EEFE rgba(39,150,238,0.996078)
1: ( 41,120,220,255) #2978DC rgba(41,120,220,1)
1: ( 43,102,209,145) #2B66D191 rgba(43,102,209,0.568627)
1: ( 43,126,224,255) #2B7EE0 rgba(43,126,224,1)
1: ( 43,170,245,253) #2BAAF5FD rgba(43,170,245,0.992157)
1: ( 44, 80,181, 41) #2C50B529 rgba(44,80,181,0.160784)
1: ( 44,172,255, 0) #2CACFF00 rgba(44,172,255,0)
1: ( 46,119,223,186) #2E77DFBA rgba(46,119,223,0.729412)
1: ( 46,162,243,244) #2EA2F3F4 rgba(46,162,243,0.956863)
1: ( 48,134,231,242) #3086E7F2 rgba(48,134,231,0.94902)
1: ( 48,141,235,219) #308DEBDB rgba(48,141,235,0.858824)
1: ( 50, 89,199, 68) #3259C744 rgba(50,89,199,0.266667)
44: ( 52,149,237,255) #3495ED rgba(52,149,237,1)
1: ( 53,107,218,106) #356BDA6A rgba(53,107,218,0.415686)
1: ( 53,147,237,238) #3593EDEE rgba(53,147,237,0.933333)
1: ( 53,148,237,246) #3594EDF6 rgba(53,148,237,0.964706)
1: ( 55, 36,136, 4) #37248804 rgba(55,36,136,0.0156863)
1: ( 56, 0,101, 0) #38006500 rgba(56,0,101,0)
1: ( 56,123,229,163) #387BE5A3 rgba(56,123,229,0.639216)
1: ( 56,139,236,201) #388BECC9 rgba(56,139,236,0.788235)
1: ( 57, 77,191, 14) #394DBF0E rgba(57,77,191,0.054902)
1: ( 57,118,227,121) #3976E379 rgba(57,118,227,0.47451)
1: ( 58,125,231,162) #3A7DE7A2 rgba(58,125,231,0.635294)
1: ( 59, 86,210, 38) #3B56D226 rgba(59,86,210,0.14902)
1: ( 60,112,227,111) #3C70E36F rgba(60,112,227,0.435294)
1: ( 62, 92,219, 41) #3E5CDB29 rgba(62,92,219,0.160784)
1: ( 63, 86,216, 14) #3F56D80E rgba(63,86,216,0.054902)
1: ( 65, 65,205, 0) #4141CD00 rgba(65,65,205,0)
1: ( 66, 63,205, 4) #423FCD04 rgba(66,63,205,0.0156863)
1: ( 93, 0, 76, 0) #5D004C00 rgba(93,0,76,0)
Rendering intent: Undefined
Interlace: None
Background color: white
Border color: rgba(223,223,223,1)
Matte color: grey74
Transparent color: none
Compose: Over
Page geometry: 54x20+0+0
Dispose: Undefined
Iterations: 0
Compression: Zip
Orientation: Undefined
Properties:
date:create: 2011-10-12T12:30:15+08:00
date:modify: 2011-10-13T15:21:50+08:00
PNG:IHDR.bit_depth : 8
PNG:IHDR.color_type : 3
PNG:IHDR.interlace_method: 0
PNG:IHDR.width,height : 54, 20
PNG:pHYs : x_res=72, y_res=72, units=0
PNG:text : 3 tEXt/zTXt/iTXt chunks were found
PNG:tRNS : chunk was found
signature: b6058538edb0efefe2a840060bd6c5dd854d2f7b9cca5866a331f5b474db7bfb
Software: Adobe ImageReady
Artifacts:
verbose: true
Tainted: False
Filesize: 908BB
Number pixels: 1.08KB
Pixels per second: 10.8TB
User time: 0.000u
Elapsed time: 0:01.000
Version: ImageMagick 6.7.3-1 2011-10-12 Q16 http://www.imagemagick.org
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

Re: how to get smooth resize?

Post by linjuming »

finally i find where the problem come from.
it is the terrible bug of ie6 ,when i change to ie7 or firefox ,there is no problem at all.
Image
Post Reply