Skip to content

Instantly share code, notes, and snippets.

View dooman87's full-sized avatar
🤟
Having fun!

Dmitry N. Pokidov dooman87

🤟
Having fun!
View GitHub Profile
// isIllustration returns true if image is cartoon like, including
// icons, logos, illustrations.
//
// It returns false for banners, product images, photos.
//
// We use this function to decide on lossy or lossless conversion for PNG when converting
// to the next generation format.
//
// The initial idea is from here: https://legacy.imagemagick.org/Usage/compare/#type_reallife
func (p *ImageMagick) isIllustration(src *img.Image, info *img.Info) (bool, error) {
func isIllustration(img []byte) (bool, error) {
mw := imagick.NewMagickWand()
err := mw.ReadImageBlob(img)
if err != nil {
return false, err
}
colorsCnt, colors = mw.GetImageHistogram()
var isIllustrationTests = []*testIsIllustration{
{"illustration-1.png", true},
{"illustration-2.png", true},
{"illustration-3.png", true},
{"logo-1.png", true},
{"logo-2.png", true},
{"banner-1.png", false},
{"screenshot-1.png", false},
{"photo-1.png", false},
{"photo-2.png", false},
<img src="https://pixboost.com/yoursite.com/hero-banner.jpeg?optimise?auth=your-api-key"
alt="Superhero rescues the World"/>
<img src="/hero-banner.jpeg" alt="Superhero rescues the World"/>
<img src="img/supercar.jpeg" alt="Fast red car"/>
<picture>
<source srcset="supercar.avif" type="image/avif">
<source srcset="supercar.webp" type="image/webp">
<img src="supercar.jpeg" alt="Fast red car"/>
</picture>
https://pixboost.com/api/2/img/https://s3-ap-southeast-2.amazonaws.com/bucket-with-images/image.png/optimise?auth=apikey
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<ACCOUNT_ID>:user/<USER_ID>"
},
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::<BUCKET_NAME>"