Documentation ¶
Index ¶
- Variables
- func AppendURLSize(urlstr string, w, h int) string
- func AsyncGET(ctx context.Context, url string, img ImageSetter)
- func AsyncGETIcon(ctx context.Context, url string, iconFn func(gio.Iconner))
- func DoProviderURL(ctx context.Context, p Provider, uri string, img ImageSetter)
- func FFmpegThumbnail(ctx context.Context, format, url string) (string, error)
- func FetchImageToFile(ctx context.Context, url string, o Opts) (string, error)
- func GET(ctx context.Context, url string, img ImageSetter)
- func IconPaintable(name string, w, h int) gdk.Paintabler
- func MaxSize(w, h, maxW, maxH int) (int, int)
- func OptsError(ctx context.Context, err error)
- func ParseURLSize(url *url.URL) (w, h int)
- func WithOpts(ctx context.Context, optFuncs ...OptFunc) context.Context
- type FFmpegOpts
- type ImageSetter
- type OptFunc
- func WithDoneFn(done func(error)) OptFunc
- func WithErrorFn(f func(error)) OptFunc
- func WithFallbackIcon(name string) OptFunc
- func WithMaxSize(w, h int) OptFunc
- func WithRectRescale(size int) OptFunc
- func WithRescale(w, h int) OptFuncdeprecated
- func WithSizeOverrider(widget gtk.Widgetter, w, h int) OptFunc
- type Opts
- type Provider
- type Providers
Constants ¶
This section is empty.
Variables ¶
var CacheAge = 7 * 24 * time.Hour // 7 days cache
CacheAge is the age to keep for all cached images.
var FFmpegProvider = FFmpegOpts{ Format: "jpeg", AllowFile: false, }
FFmpegProvider implements imgutil.Provider and uses FFmpeg to render the image using a given HTTP(S) URL. It supports images, videos and more.
Functions ¶
func AppendURLSize ¶
AppendURLSize appends into the URL fragments the width and height parameters. Providers that support these fragments will be able to read them.
func AsyncGET ¶
func AsyncGET(ctx context.Context, url string, img ImageSetter)
AsyncGET GETs the given URL and calls f in the main loop. If the context is cancelled by the time GET is done, then f will not be called. If the given URL is nil, then the function does nothing.
This function can be called from any thread. It will synchronize accordingly by itself.
func AsyncGETIcon ¶
AsyncGETIcon GETs the given URL as a GIcon and calls f in the main loop. If the context is cancelled by the time GET is done, then f will not be called.
func DoProviderURL ¶
func DoProviderURL(ctx context.Context, p Provider, uri string, img ImageSetter)
DoProviderURL invokes a Provider with the given URI string (instead of a *url.URL instance).
func FFmpegThumbnail ¶
FFmpegThumbnail fetches the thumbnail of the given URL and returns the path to the file. If format is empty, then jpeg is used.
func FetchImageToFile ¶
FetchImageToFile fetches an image from the given URL and saves it to the given file. If the image is already cached, then it will be loaded from the cache instead.
func GET ¶
func GET(ctx context.Context, url string, img ImageSetter)
GET gets the given URL into a Paintable.
func IconPaintable ¶
IconPaintable gets the icon with the given name and returns the size. Nil is never returned.
func MaxSize ¶
MaxSize returns the maximum size that can fit within the given max width and height. Aspect ratio is preserved.
func ParseURLSize ¶
ParseURLSize parses the optional width and height fragments from the URL. If the URL has none, then (0, 0) is returned.
func WithOpts ¶
WithOpts injects the given imgutil.OptFunc options into the context. imgutil calls that takes in the returned context will have the given options. Calling WithOpts with a context returned from another WithOpts will make it create a copy that inherits the properties of the top-level Opts.
Types ¶
type FFmpegOpts ¶
FFmpegOpts is the options for FFmpeg.
func (FFmpegOpts) Do ¶
func (p FFmpegOpts) Do(ctx context.Context, url *url.URL, img ImageSetter)
Do implements Provider.
type ImageSetter ¶
type ImageSetter struct { SetFromPixbuf func(*gdkpixbuf.Pixbuf) SetFromAnimation func(*gdkpixbuf.PixbufAnimation) SetFromPaintable func(gdk.Paintabler) }
ImageSetter contains functions for setting images fetched from a Provider.
func ImageSetterFromImage ¶
func ImageSetterFromImage(img *gtk.Image) ImageSetter
ImageSetterFromImage returns an ImageSetter for a gtk.Image.
func ImageSetterFromPicture ¶
func ImageSetterFromPicture(picture *gtk.Picture) ImageSetter
ImageSetterFromPicture returns an ImageSetter for a gtk.Picture.
type OptFunc ¶
type OptFunc func(*Opts)
OptFunc is a type that can optionally modify the default internal options for each call.
func WithDoneFn ¶
WithDoneFn is like WithErrorFn, except it's called once the routine is done on the main thread with a possibly nil error.
func WithErrorFn ¶
WithErrorFn adds a callback that is called on an error.
func WithFallbackIcon ¶
WithFallbackIcon makes image functions use the icon as the image given into the callback instead of a nil one. If name is empty, then dialog-error is used. Note that this function overrides WithErrorFn if it is after.
func WithMaxSize ¶
WithMaxSize sets the maximum size of the image. The image will be scaled down to fit the size while respecting its aspect ratio. If the screen is HiDPI, then the size will be scaled up.
func WithRectRescale ¶
WithRectRescale is a convenient function around WithRescale for rectangular or circular images.
func WithRescale
deprecated
func WithSizeOverrider ¶
WithSizeOverrider overrides the widget's size request to be of the given size.
type Opts ¶
type Opts struct {
// contains filtered or unexported fields
}
func OptsFromContext ¶
OptsFromContext gets the Opts from the given context. If there is none, then a zero-value instance is returned.
type Provider ¶
type Provider interface { Schemes() []string Do(ctx context.Context, url *url.URL, img ImageSetter) }
Provider describes a universal resource provider.
var FileProvider Provider = fileProvider{}
FileProvider is the universal resource provider for a file (file://).
var HTTPProvider Provider = httpProvider{}
HTTPProvider is the universal resource provider that handles HTTP and HTTPS schemes (http:// and https://).
type Providers ¶
Providers holds multiple providers. A Providers instance is also a Provider in itself.
func NewProviders ¶
NewProviders creates a new Providers instance. Providers that are put last can override schemes of providers put before.