0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

GoでJpegからWebpへの変換

Posted at

開発環境

  • Windows10
  • Visual Studio Code
  • go version go1.15.5 windows/amd64

Code

main.go
package main

import (
	"log"
	"os"

	"github.com/chai2010/webp"
	"github.com/disintegration/imaging"
)

func main() {
	img, err := imaging.Open("haruchan.jpg", imaging.AutoOrientation(true))
	if err != nil {
		log.Fatal(err)
	}
	file, err := os.Create("haruchan30.webp")
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()
	options := webp.Options{Lossless: false, Quality: 30}
	if err := webp.Encode(file, img, &options); err != nil {
		log.Fatal(err)
	}
	log.Println("ok.")
}

その他

コード自体はほぼここの写経なのですが、Optionsが設定されていなかったので、ロスレスでQualityを設定してみたのですが、そのサイズの激減ぶりに驚いた。家族の写真で試したので貼れないのですが4608x2592のデジカメ画像。視力は良い方ですが特に強い劣化を感じず。blog(写真ブログなどでなければ)ならdefaultでQuality:50でいいのでは?という感じ。自前サーバのWordPress pluginでjpeg/pngをwebpに変換しているのですが、こんなにも減っているとはなあと。

1612532617742.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?