2011-06-03 15 views
0

私は透明な領域(矩形)を持つ画像を持っています。 左上の透明ピクセルの座標と右下のピクセルの座標を検出する必要があります。 imagemagickやrubyでそれを行うには?アルファチャンネルの座標

答えて

1

イメージmagick identify commandのオプション-verbose -alphaを使用すると、必要な情報を印刷する必要があります。

[email protected]:~$ identify -verbose -alpha Extract http://upload.wikimedia.org/wikipedia/commons/5/51/Google.png 
Image: /tmp/magick-XXy36tWu 
    Base filename: Google.png 
    Format: PNG (Portable Network Graphics) 
    Class: DirectClass 
    Geometry: 1192x432+0+0 
    Resolution: 28.35x28.35 
    Print size: 42.0459x15.2381 
    Units: PixelsPerCentimeter 
    Type: Grayscale 
    Base type: Grayscale 
    Endianess: Undefined 
    Colorspace: RGB 
    Depth: 8-bit 
    Channel depth: 
    gray: 8-bit 
    Channel statistics: 
    Gray: 
     min: 0 (0) 
     max: 255 (1) 
     mean: 78.1591 (0.306506) 
     standard deviation: 117.214 (0.459663) 
     kurtosis: -1.28542 
     skewness: 0.843321 
    Histogram: 
    350312: ( 0, 0, 0) #000000 black 
     66: ( 9, 9, 9) #090909 rgb(9,9,9) 
     182: (10, 10, 10) #0A0A0A grey4 
     2866: (11, 11, 11) #0B0B0B rgb(11,11,11) 
     177: (13, 13, 13) #0D0D0D grey5 
     113: (15, 15, 15) #0F0F0F grey6 
     50: (19, 19, 19) #131313 rgb(19,19,19) 
     138: (20, 20, 20) #141414 grey8 
     1902: (22, 22, 22) #161616 rgb(22,22,22) 
     149: (27, 27, 27) #1B1B1B rgb(27,27,27) 
     18: (28, 28, 28) #1C1C1C grey11 
     83: (30, 30, 30) #1E1E1E rgb(30,30,30) 
     50: (31, 31, 31) #1F1F1F grey12 
     631: (33, 33, 33) #212121 grey13 
     9: (38, 38, 38) #262626 grey15 
     53: (40, 40, 40) #282828 rgb(40,40,40) 
     11: (41, 41, 41) #292929 grey16 
     200: (44, 44, 44) #2C2C2C rgb(44,44,44) 
     24: (45, 45, 45) #2D2D2D rgb(45,45,45) 
     2: (47, 47, 47) #2F2F2F rgb(47,47,47) 
     11: (51, 51, 51) #333333 grey20 
     17: (54, 54, 54) #363636 grey21 
     148: (55, 55, 55) #373737 rgb(55,55,55) 
     5: (57, 57, 57) #393939 rgb(57,57,57) 
     10: (60, 60, 60) #3C3C3C rgb(60,60,60) 
     10: (61, 61, 61) #3D3D3D grey24 
     2: (66, 66, 66) #424242 grey26 
     119: (67, 67, 67) #434343 rgb(67,67,67) 
     1: (71, 71, 71) #474747 grey28 
     8: (75, 75, 75) #4B4B4B rgb(75,75,75) 
     79: (78, 78, 78) #4E4E4E rgb(78,78,78) 
     7: (81, 81, 81) #515151 rgb(81,81,81) 
     3: (82, 82, 82) #525252 grey32 
     1: (85, 85, 85) #555555 rgb(85,85,85) 
     66: (89, 89, 89) #595959 grey35 
     1: (90, 90, 90) #5A5A5A rgb(90,90,90) 
     7: (92, 92, 92) #5C5C5C grey36 
     5: (94, 94, 94) #5E5E5E grey37 
     50: (100,100,100) #646464 rgb(100,100,100) 
     4: (102,102,102) #666666 grey40 
     1: (104,104,104) #686868 rgb(104,104,104) 
     9: (105,105,105) #696969 DimGray 
      3: (107,107,107) #6B6B6B grey42 
     49: (111,111,111) #6F6F6F rgb(111,111,111) 
     2: (112,112,112) #707070 grey44 
     2: (120,120,120) #787878 grey47 
     4: (121,121,121) #797979 rgb(121,121,121) 
     44: (122,122,122) #7A7A7A grey48 
     1: (132,132,132) #848484 rgb(132,132,132) 
     42: (133,133,133) #858585 grey52 
     1: (134,134,134) #868686 rgb(134,134,134) 
     1: (135,135,135) #878787 grey53 
     3: (142,142,142) #8E8E8E rgb(142,142,142) 
     3: (143,143,143) #8F8F8F grey56 
     46: (144,144,144) #909090 rgb(144,144,144) 
     4: (150,150,150) #969696 grey59 
     2: (153,153,153) #999999 grey60 
     31: (155,155,155) #9B9B9B rgb(155,155,155) 
     1: (161,161,161) #A1A1A1 grey63 
     2: (163,163,163) #A3A3A3 grey64 
     2: (165,165,165) #A5A5A5 rgb(165,165,165) 
     25: (166,166,166) #A6A6A6 grey65 
     1: (170,170,170) #AAAAAA rgb(170,170,170) 
     2: (173,173,173) #ADADAD grey68 
     2: (174,174,174) #AEAEAE rgb(174,174,174) 
     30: (177,177,177) #B1B1B1 rgb(177,177,177) 
     3: (180,180,180) #B4B4B4 rgb(180,180,180) 
     21: (188,188,188) #BCBCBC rgb(188,188,188) 
     3: (194,194,194) #C2C2C2 grey76 
     1: (195,195,195) #C3C3C3 rgb(195,195,195) 
     1: (198,198,198) #C6C6C6 rgb(198,198,198) 
     23: (200,200,200) #C8C8C8 rgb(200,200,200) 
     1: (201,201,201) #C9C9C9 grey79 
     1: (204,204,204) #CCCCCC grey80 
     2: (208,208,208) #D0D0D0 rgb(208,208,208) 
     23: (211,211,211) #D3D3D3 LightGray 
     2: (214,214,214) #D6D6D6 grey84 
     2: (217,217,217) #D9D9D9 grey85 
     30: (222,222,222) #DEDEDE grey87 
     1: (225,225,225) #E1E1E1 rgb(225,225,225) 
     2: (227,227,227) #E3E3E3 grey89 
     1: (228,228,228) #E4E4E4 rgb(228,228,228) 
     24: (233,233,233) #E9E9E9 rgb(233,233,233) 
     1: (240,240,240) #F0F0F0 grey94 
     25: (244,244,244) #F4F4F4 rgb(244,244,244) 
     2: (245,245,245) #F5F5F5 grey96 
     1: (246,246,246) #F6F6F6 rgb(246,246,246) 
    156871: (255,255,255) #FFFFFF white 
    Rendering intent: Undefined 
    Gamma: 0.45454 
    Chromaticity: 
    red primary: (0.63999,0.33001) 
    green primary: (0.3,0.6) 
    blue primary: (0.15,0.05999) 
    white point: (0.31269,0.32899) 
    Interlace: None 
    Background color: white 
    Border color: rgb(223,223,223) 
    Matte color: grey74 
    Transparent color: black 
    Compose: Over 
    Page geometry: 1192x432+0+0 
    Dispose: Undefined 
    Iterations: 0 
    Compression: Zip 
    Orientation: Undefined 
    Properties: 
    date:create: 2011-06-03T16:04:15-07:00 
    date:modify: 2011-06-03T16:04:15-07:00 
    signature: 7e7bb49c70ea3ef7fec10871b5cf1650af0b072b6d5c997db85f8c69015d0345 
    Artifacts: 
    verbose: true 
    Tainted: True 
    Filesize: 243KB 
    Number pixels: 515KB 
    Pixels per second: 17.16MB 
    User time: 0.020u 
    Elapsed time: 0:01.030 
    Version: ImageMagick 6.6.0-4 2010-11-16 Q16 http://www.imagemagick.org 
[email protected]:~$ 

このコマンドは、透明な背景でGoogle logoを取り、アルファチャンネルのみを抽出します。その後、この画像(preview)のプロパティを取得します。コマンドラインに出力します。

+0

ありがとう、試してみる –