Skip to content

Lorem Picsum GO (Golang) SDK for generating random images

License

Notifications You must be signed in to change notification settings

Hand-of-Doom/Picsum-SDK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Picsum-SDK

Picsum GO (Golang) SDK for generating random images

How to install

go get github.com/Hand-of-Doom/Picsum-SDK@latest

Examples

Generating a random image

provider := picsum.NewImageProvider(
    picsum.NewImageOptions(500, 500), // width & height
)

image, err := provider.Load()
fmt.Println(image.ID) // id of that image

os.WriteFile("./output.jpg", image.Content, 0400)

Getting an image by seed

options := picsum.NewImageOptions(500, 500).
    Identifier("apple", picsum.Seed)

provider := picsum.NewImageProvider(options)
image, err := provider.Load()

os.WriteFile("./output.jpg", image.Content, 0400)

Getting an image by id

options := picsum.NewImageOptions(500, 500).
    Identifier("1", picsum.ID)

provider := picsum.NewImageProvider(options)
image, err := provider.Load()

os.WriteFile("./output.jpg", image.Content, 0400)

Getting an image with blur & grayscale filter

options := picsum.NewImageOptions(500, 500)
// You can set blur depth to zero to disable blur effect
options.Filter(
    /*is grayscale enabled*/ true, 
    /*blur depth*/ 5,
)

provider := picsum.NewImageProvider(options)
image, err := provider.Load()

os.WriteFile("./output.jpg", image.Content, 0400)

Getting images in different formats

optionsWebP := picsum.NewImageOptions(500, 500).Format(picsum.WebP)

optionsJPEG := picsum.NewImageOptions(500, 500).Format(picsum.JPG)

imageWebP, err := picsum.NewImageProvider(optionsWebP).Load()
imageJPEG, err := picsum.NewImageProvider(optionsJPEG).Load()

os.WriteFile("./output.webp", imageWebP.Content, 0400)
os.WriteFile("./output.jpg", imageJPEG.Content, 0400)

Getting image details

image, err := picsum.
    NewImageProvider(picsum.NewImageOptions(500, 500)).
    Load()

thisImageID := image.ID

details, err := picsum.GetImageDetails(thisImageID, picsum.ID)

// By seed
details, err := picsum.GetImageDetails("apple", picsum.Seed)

Getting a list of images

page := 1
limit := 100
list, err := picsum.GetImagesList(page, limit)

if list.LastPage {
    fmt.Println("Oh, this is a last page!")
}

fmt.Println(list.Value)

About

Lorem Picsum GO (Golang) SDK for generating random images

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages