jpegquality

package module
v0.0.0-...-795f5b3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2023 License: MIT Imports: 3 Imported by: 2

README

Detect JPEG quality from bytes or io.ReadSeeker (like os.File)

Input a JPEG file to detect the quality of the image along with the Quanization Table and DQTs.

Build Status

Inpiration from Estimating Quality.

Fixed bug base on HuangYeWuDeng ttys3/jpegquality.

Languages/Dependencies:

Golang

How to Install/Run:

In order to install and run this program, please follow the steps below:

1. Clone the repository to your local device
git clone https://github.com/liut/jpegquality.git
2. Install Golang:
Follow this [link](https://go.dev/doc/install) for help.
3. Build Executable:
cd jpegq && go build
4. Run executable and specify input jpeg file.
jpegq [FILENAME]

Example: jpegq myphoto.jpg                     

How to Contribute:

1. Fork the main repository
2. Clone the repo to your local device
git clone https://github.com/liut/jpegquality.git
3. Install Golang:
Follow this [link](https://go.dev/doc/install) for help.
5. Create a new branch for your changes.
git checkout -b <name-of-branch>
6. Submit a Pull Request to the main repository

Code usage:


	file, err := os.Open("file.jpg")
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()
	j, err := jpegquality.New(file) // or NewWithBytes([]byte)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("jpeg quality %d", j.Quality())

Testing

This program's output accurracy was tested thoroughly in jpegquality_tests.go. Feel free to add anymore tests for edge cases!

Bugs

Please report any bugs below to ensure contributors can keep this code functional and easy to use

Command line tool

go get github.com/liut/jpegquality/cmd/jpegq

jpegq myphoto.jpg

Output example
2019/10/03 00:09:08 jpegquality.go:135: Quantization table length 130
2019/10/03 00:09:08 jpegquality.go:144: read bytes 130
2019/10/03 00:09:08 jpegquality.go:161: DQT: table index 0 (luminance), precision: 8
2019/10/03 00:09:08 jpegquality.go:208: tbl 0: 23.90413 572.61780 88.04793
2019/10/03 00:09:08 jpegquality.go:212: aver_quality 88
88

Custom logger for debug


jpegquality.SetLogger(log.New(os.Stderr, "jpegq", log.LstdFlags|log.Lshortfile))

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidJPEG  = errors.New("Invalid JPEG header")
	ErrWrongTable   = errors.New("ERROR: Wrong size for quantization table")
	ErrShortSegment = errors.New("short segment length")
	ErrShortDQT     = errors.New("DQT section too short")
)

Errors

Functions

func SetLogger

func SetLogger(l Logger)

SetLogger ...

Types

type Logger

type Logger interface {
	Print(args ...interface{})
	Printf(format string, args ...interface{})
}

Logger ...

func GetLogger

func GetLogger() Logger

GetLogger ...

type Qualitier

type Qualitier interface {
	Quality() int
}

Qualitier ...

func New

func New(rs io.ReadSeeker) (qr Qualitier, err error)

New ...

func NewWithBytes

func NewWithBytes(buf []byte) (qr Qualitier, err error)

NewWithBytes ...

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL