1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        Go開源項目推薦:實(shí)現(xiàn) Photoshop 的功能

        共 5665字,需瀏覽 12分鐘

         ·

        2021-09-13 20:15

        生態(tài)君今天發(fā)現(xiàn)一個有意思的 Go 語言項目:bild,項目地址:https://github.com/anthonynsimon/bild,Star 數(shù) 3.3k+。使用純 Go 實(shí)現(xiàn)圖像處理,而且盡可能使用標(biāo)準(zhǔn)庫實(shí)現(xiàn)。

        具體都實(shí)現(xiàn)了哪些功能呢?

        因?yàn)樵擁椖考瓤梢援?dāng)工具使用,也可以當(dāng)庫使用。不管如何,先安裝它:

        go install github.com/anthonynsimon/bild@latest

        $GOBIN 目錄下會有 bild 可執(zhí)行程序(默認(rèn)是 ~/go/bin 目錄下)。為了方便使用,請將該目錄加入 $PATH 中。

        $ bild
        A collection of parallel image processing algorithms in pure Go

        Usage:
          bild [command]

        Available Commands:
          adjust      adjust basic image features like brightness or contrast
          blend       blend two images together
          blur        blur an image using the specified method
          channel     channel operations on images
          effect      apply effects on images
          help        Help about any command
          histogram   histogram operations on images
          imgio       i/o operations on images
          noise       noise generators
          segment     segment an image using the specified method

        Flags:
          -h, --help   help for bild

        Use "bild [command] --help" for more information about a command.

        01 類似 Photoshop 「圖像—>調(diào)整」下的功能

        adjust:調(diào)整基本圖像功能,如亮度或?qū)Ρ榷取?/p>

        $ bild help adjust
        adjust basic image features like brightness or contrast

        Usage:
          bild adjust [command]

        Available Commands:
          brightness  adjust the relative brightness of an image
          contrast    adjust the relative contrast of an image
          gamma       adjust the gamma of an image
          hue         adjust the hue of an image
          saturation  adjust the saturation of an image

        Flags:
          -h, --help   help for adjust

        Use "bild adjust [command] --help" for more information about a command.

        對應(yīng)的子命令功能是:

        • brightness 亮度
        • contrast 對比度
        • gamma 伽馬
        • hue 色階
        • saturation 飽和度

        這些功能使用方法都可以通過 bild adjust xxx --help 查看。在官方文檔也有具體的圖片示例,看看對應(yīng)的效果。

        02 兩個圖片疊加

        即 blend 功能。

        $ bild help blend
        blend two images together

        Usage:
          bild blend [command]

        Available Commands:
          add
          colorburn
          colordodge
          darken
          difference
          divide
          exclusion
          lighten
          linearLight
          linearburn
          multiply
          normal
          opacity
          overlay
          screen
          softlight
          subtract

        Flags:
          -h, --help   help for blend

        Use "bild blend [command] --help" for more information about a command.

        并非簡單的疊加,有一對子命令可以使用。在官方文檔也有具體的圖片示例,看看對應(yīng)的效果。

        03 模糊

        使用過 PS 的同學(xué),應(yīng)該挺喜歡「高斯模糊」。

        $ bild help blur
        blur an image using the specified method

        Usage:
          bild blur [command]

        Available Commands:
          box         apply box blur to an input image
          gaussian    apply gaussian blur to an input image

        Flags:
          -h, --help   help for blur

        Use "bild blur [command] --help" for more information about a command.

        其中 gaussian 就是高斯模糊。


        其他更多功能,不一一列舉。

        如果當(dāng)做庫使用,如何做?

        04 當(dāng)做庫使用

        看官方給的一個例子:

        package main

        import (
            "github.com/anthonynsimon/bild/effect"
            "github.com/anthonynsimon/bild/imgio"
            "github.com/anthonynsimon/bild/transform"
        )

        func main() {
            img, err := imgio.Open("input.jpg")
            if err != nil {
                fmt.Println(err)
                return
            }

            inverted := effect.Invert(img)
            resized := transform.Resize(inverted, 800800, transform.Linear)
            rotated := transform.Rotate(resized, 45nil)

            if err := imgio.Save("output.png", rotated, imgio.PNGEncoder()); err != nil {
                fmt.Println(err)
                return
            }
        }

        大家如果對圖片處理感興趣,可以好好學(xué)習(xí)這個包。既是完整的可用項目,也是一個庫,可以自己進(jìn)行更多封裝、擴(kuò)展。覺得不錯,可以給該項目點(diǎn)個 Star。

        文末閱讀原文可以直達(dá)項目首頁。



        推薦閱讀


        福利

        我為大家整理了一份從入門到進(jìn)階的Go學(xué)習(xí)資料禮包,包含學(xué)習(xí)建議:入門看什么,進(jìn)階看什么。關(guān)注公眾號 「polarisxu」,回復(fù) ebook 獲??;還可以回復(fù)「進(jìn)群」,和數(shù)萬 Gopher 交流學(xué)習(xí)。

        瀏覽 89
        點(diǎn)贊
        評論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報
        評論
        圖片
        表情
        推薦
        點(diǎn)贊
        評論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            黄色短视频成人网在线观看免费 | 成人少妇 | 欧美又大又硬又粗bbbbb 他的舌头挺进了我下面 | 黄色p网站 | 男人的天堂在线播放 | 五月天狠狠干 | 女人被啪到高潮gif动态图 | 久久悠悠| 超碰.com | 好爽免费视频 |