Documentation ¶
Index ¶
- Variables
- func ColoredImageDataURL(c color.Color) string
- func ImageDataURL(imageURL string) (dataURL string, err error)
- func ImagesAdmin() view.View
- func MakePrettyUrlFilename(filename string) string
- func ResampleImage(m image.Image, r image.Rectangle, w, h int) image.Image
- func UploadImageButton(parentSelector, dropZoneSelector, listSelector string, thumbnailSize int, ...) view.View
- func ViewPath(name string) view.ViewPath
- type Backend
- type Configuration
- type ErrInvalidImageID
- type HorAlignment
- type Image
- func (self *Image) AspectRatio() float64
- func (self *Image) ContentType() string
- func (self *Image) CountRefs() (int, error)
- func (self *Image) Delete() error
- func (self *Image) DeleteVersion(index int) error
- func (self *Image) Filename() string
- func (self *Image) GetURL() view.URL
- func (self *Image) Grayscale() bool
- func (self *Image) Height() int
- func (self *Image) Init()
- func (self *Image) OriginalVersion() *ImageVersion
- func (self *Image) Rectangle() image.Rectangle
- func (self *Image) RemoveAllRefs() error
- func (self *Image) Save() error
- func (self *Image) Thumbnail(size int) (im *ImageVersion, err error)
- func (self *Image) ThumbnailLinkedView(size int, imageClass, linkClass string) (*view.Link, error)
- func (self *Image) ThumbnailView(size int, class string) (*view.Image, error)
- func (self *Image) TitleOrFilename() string
- func (self *Image) Version(width, height int, horAlign HorAlignment, verAlign VerAlignment, ...) (im *ImageVersion, err error)
- func (self *Image) VersionCentered(width, height int, grayscale bool) (im *ImageVersion, err error)
- func (self *Image) VersionCenteredLinkedView(width, height int, grayscale bool, imageClass, linkClass string) (*view.Link, error)
- func (self *Image) VersionCenteredView(width, height int, grayscale bool, class string) (*view.Image, error)
- func (self *Image) VersionHeight(height int, grayscale bool) (im *ImageVersion, err error)
- func (self *Image) VersionHeightLinkedView(height int, grayscale bool, imageClass, linkClass string) (*view.Link, error)
- func (self *Image) VersionHeightView(height int, grayscale bool, class string) (*view.Image, error)
- func (self *Image) VersionLinkedView(width, height int, horAlign HorAlignment, verAlign VerAlignment, ...) (*view.Link, error)
- func (self *Image) VersionSourceRect(sourceRect image.Rectangle, width, height int, grayscale bool, ...) (im *ImageVersion, err error)
- func (self *Image) VersionSourceRectLinkedView(sourceRect image.Rectangle, width, height int, grayscale bool, ...) (*view.Link, error)
- func (self *Image) VersionSourceRectView(sourceRect image.Rectangle, width, height int, grayscale bool, ...) (*view.Image, error)
- func (self *Image) VersionTouchOrigFromOutside(width, height int, horAlign HorAlignment, verAlign VerAlignment, ...) (im *ImageVersion, err error)
- func (self *Image) VersionTouchOrigFromOutsideCentered(width, height int, grayscale bool, outsideColor color.Color) (im *ImageVersion, err error)
- func (self *Image) VersionTouchOrigFromOutsideCenteredLinkedView(width, height int, grayscale bool, outsideColor color.Color, ...) (*view.Link, error)
- func (self *Image) VersionTouchOrigFromOutsideCenteredView(width, height int, grayscale bool, outsideColor color.Color, class string) (*view.Image, error)
- func (self *Image) VersionTouchOrigFromOutsideLinkedView(width, height int, horAlign HorAlignment, verAlign VerAlignment, ...) (*view.Link, error)
- func (self *Image) VersionTouchOrigFromOutsideView(width, height int, horAlign HorAlignment, verAlign VerAlignment, ...) (*view.Image, error)
- func (self *Image) VersionView(width, height int, horAlign HorAlignment, verAlign VerAlignment, ...) (*view.Image, error)
- func (self *Image) VersionWidth(width int, grayscale bool) (im *ImageVersion, err error)
- func (self *Image) VersionWidthLinkedView(width int, grayscale bool, imageClass, linkClass string) (*view.Link, error)
- func (self *Image) VersionWidthView(width int, grayscale bool, class string) (*view.Image, error)
- func (self *Image) Width() int
- type ImageRef
- func (self *ImageRef) Get() (*Image, error)
- func (self *ImageRef) IsEmpty() bool
- func (self *ImageRef) OriginalVersion() (*ImageVersion, error)
- func (self *ImageRef) OriginalVersionLinkedView(imageClass, linkClass string) (*view.Link, error)
- func (self *ImageRef) OriginalVersionView(class string) (*view.Image, error)
- func (self *ImageRef) Required(metaData *model.MetaData) bool
- func (self *ImageRef) Set(image *Image)
- func (self *ImageRef) SetString(str string) error
- func (self *ImageRef) String() string
- func (self *ImageRef) Thumbnail(size int) (im *ImageVersion, err error)
- func (self *ImageRef) ThumbnailLinkedView(size int, imageClass, linkClass string) (*view.Link, error)
- func (self *ImageRef) ThumbnailView(size int, class string) (*view.Image, error)
- func (self *ImageRef) TryGet() (*Image, bool, error)
- func (self *ImageRef) Validate(metaData *model.MetaData) error
- func (self *ImageRef) Version(width, height int, horAlign HorAlignment, verAlign VerAlignment, ...) (im *ImageVersion, err error)
- func (self *ImageRef) VersionCentered(width, height int, grayscale bool) (im *ImageVersion, err error)
- func (self *ImageRef) VersionCenteredLinkedView(width, height int, grayscale bool, imageClass, linkClass string) (*view.Link, error)
- func (self *ImageRef) VersionCenteredView(width, height int, grayscale bool, class string) (*view.Image, error)
- func (self *ImageRef) VersionHeight(height int, grayscale bool) (im *ImageVersion, err error)
- func (self *ImageRef) VersionHeightLinkedView(height int, grayscale bool, imageClass, linkClass string) (*view.Link, error)
- func (self *ImageRef) VersionHeightView(height int, grayscale bool, class string) (*view.Image, error)
- func (self *ImageRef) VersionLinkedView(width, height int, horAlign HorAlignment, verAlign VerAlignment, ...) (*view.Link, error)
- func (self *ImageRef) VersionSourceRect(sourceRect image.Rectangle, width, height int, grayscale bool, ...) (im *ImageVersion, err error)
- func (self *ImageRef) VersionSourceRectLinkedView(sourceRect image.Rectangle, width, height int, grayscale bool, ...) (*view.Link, error)
- func (self *ImageRef) VersionSourceRectView(sourceRect image.Rectangle, width, height int, grayscale bool, ...) (*view.Image, error)
- func (self *ImageRef) VersionTouchOrigFromOutside(width, height int, horAlign HorAlignment, verAlign VerAlignment, ...) (im *ImageVersion, err error)
- func (self *ImageRef) VersionTouchOrigFromOutsideCentered(width, height int, grayscale bool, outsideColor color.Color) (im *ImageVersion, err error)
- func (self *ImageRef) VersionTouchOrigFromOutsideCenteredLinkedView(width, height int, grayscale bool, outsideColor color.Color, ...) (*view.Link, error)
- func (self *ImageRef) VersionTouchOrigFromOutsideCenteredView(width, height int, grayscale bool, outsideColor color.Color, class string) (*view.Image, error)
- func (self *ImageRef) VersionTouchOrigFromOutsideLinkedView(width, height int, horAlign HorAlignment, verAlign VerAlignment, ...) (*view.Link, error)
- func (self *ImageRef) VersionTouchOrigFromOutsideView(width, height int, horAlign HorAlignment, verAlign VerAlignment, ...) (*view.Image, error)
- func (self *ImageRef) VersionView(width, height int, horAlign HorAlignment, verAlign VerAlignment, ...) (*view.Image, error)
- func (self *ImageRef) VersionWidth(width int, grayscale bool) (im *ImageVersion, err error)
- func (self *ImageRef) VersionWidthLinkedView(width int, grayscale bool, imageClass, linkClass string) (*view.Link, error)
- func (self *ImageRef) VersionWidthView(width int, grayscale bool, class string) (*view.Image, error)
- type ImageRefController
- type ImageRefControllerConfiguration
- type ImageVersion
- func (self *ImageVersion) AspectRatio() float64
- func (self *ImageVersion) GetURL() view.URL
- func (self *ImageVersion) LinkedView(imageClass, linkClass string) *view.Link
- func (self *ImageVersion) LoadImage() (image.Image, error)
- func (self *ImageVersion) SaveImage(im image.Image) error
- func (self *ImageVersion) SaveImageData(data []byte) error
- func (self *ImageVersion) View(class string) *view.Image
- type ImagesAdminConfiguration
- type ModelRect
- type VerAlignment
Constants ¶
This section is empty.
Variables ¶
var AllThumbnailsAPI = view.NewViewURLWrapper(view.RenderViewBindURLArgs( func(ctx *view.Context, thumbnailSize int) error { ctx.Response.SetContentTypeByExt(".json") ctx.Response.WriteString("[\n") first := true i := Config.Backend.ImageIterator() for doc := i.Next(); doc != nil; doc = i.Next() { image := doc.(*Image) thumbnail, err := image.Thumbnail(thumbnailSize) if err != nil { return err } if first { first = false } else { ctx.Response.WriteString(",\n") } ctx.Response.Printf( `{"id": "%s", "title": "%s", "url": "%s"}`, image.ID, image.TitleOrFilename(), thumbnail.GetURL().URL(ctx), ) } if i.Err() != nil { return i.Err() } ctx.Response.WriteString("\n]") return nil }, ))
var Config = Configuration{ DummyImageColor: "#a8a8a8", ImagesAdmin: ImagesAdminConfiguration{ ImageEditorClass: "media-image-editor", ThumbnailSize: 200, ThumbnailFrameClass: "thumbnail-frame", ActionsClass: "actions", }, ImageRefController: ImageRefControllerConfiguration{ Class: "media-imageref-editor", ThumbnailSize: 100, ThumbnailFrameClass: "thumbnail-frame", ActionsClass: "actions", }, }
var ImageView = view.NewViewURLWrapper(view.RenderView( func(ctx *view.Context) error { reader, contentType, err := Config.Backend.ImageVersionReader(ctx.URLArgs[0]) if err != nil { if _, ok := err.(ErrInvalidImageID); ok { return view.NotFound(ctx.URLArgs[0] + "/" + ctx.URLArgs[1] + " not found") } return err } _, err = io.Copy(ctx.Response, reader) if err != nil { return err } err = reader.Close() if err != nil { return err } ctx.Response.Header().Set("Content-Type", contentType) return nil }, ))
var UploadImage = view.NewViewURLWrapper(view.RenderViewBindURLArgs( func(ctx *view.Context, thumbnailSize int) error { formatError := func(err error) error { return fmt.Errorf(`{success: false, error: "%s"}`, err.Error()) } filename := ctx.Request.Header.Get("X-File-Name") var r io.ReadCloser if filename != "" { r = ctx.Request.Body } else { f, h, err := ctx.Request.FormFile("qqfile") if err != nil { return formatError(err) } filename = h.Filename r = f } defer r.Close() b, err := ioutil.ReadAll(r) if err != nil { return formatError(err) } i, err := NewImage(filename, b) if err != nil { return formatError(err) } v, err := i.Thumbnail(thumbnailSize) if err != nil { return formatError(err) } ctx.Response.Printf(`{success: true, imageID: "%s", thumbnailURL: "%s", thumbnailSize: %d}`, i.ID, v.GetURL().URL(ctx), thumbnailSize) return nil }, ))
Functions ¶
func ColoredImageDataURL ¶
ColoredImageDataURL creates a 1 pixel image with the given color and encodes it as data URL.
func ImageDataURL ¶
ImageDataURL downloads an image and encodes it as a data URL.
func ImagesAdmin ¶
func MakePrettyUrlFilename ¶
MakePrettyUrlFilename modifies a filename so it looks good as part on an URL.
func ResampleImage ¶
Resample returns a resampled copy of the image slice r of m. The returned image has width w and height h.
Types ¶
type Backend ¶
type Backend interface { LoadImage(id string) (*Image, error) TryLoadImage(id string) (*Image, bool, error) // SaveImage saves image and updates its ID if it is empty. SaveImage(image *Image) error DeleteImage(image *Image) error DeleteImageVersion(id string) error // ImageVersionReader returns an io.ReadCloser to read the image-data // with the given id from the backend. // If there is no image with the given id, // an error of type ErrInvalidImageID will be returned. ImageVersionReader(id string) (reader io.ReadCloser, ctype string, err error) // ImageVersionWriter returns an io.WriteCloser to write the image-data // to the backend. version.ID can be empty for a new image or the id // of an existing image. version.ID can be changed by the function call // regardless of the former value ImageVersionWriter(version *ImageVersion) (writer io.WriteCloser, err error) ImageIterator() model.Iterator // CountImageRefs counts all ImageRef occurances with imageID // in all known databases. CountImageRefs(imageID string) (int, error) // RemoveAllImageRefs removes all ImageRef occurances with imageID // in all known databases. RemoveAllImageRefs(imageID string) error }
type Configuration ¶
type Configuration struct { Backend Backend NoDynamicStyleAndScript bool DummyImageColor string // web color ImagesAdmin ImagesAdminConfiguration ImageRefController ImageRefControllerConfiguration // contains filtered or unexported fields }
func (*Configuration) Close ¶
func (self *Configuration) Close() error
func (*Configuration) Init ¶
func (self *Configuration) Init() error
func (*Configuration) Name ¶
func (self *Configuration) Name() string
type ErrInvalidImageID ¶
type ErrInvalidImageID string
func (ErrInvalidImageID) Error ¶
func (self ErrInvalidImageID) Error() string
type Image ¶
type Image struct { ID model.String `bson:",omitempty"` Title model.String Link model.Url Versions []ImageVersion }
func NewImage ¶
NewImage creates a new Image and saves the original version to Config.Backend. GIF, TIFF, BMP images will be read, but saved as PNG.
func NewImageFromReader ¶
NewImageFromReader creates a new Image and saves the original version to Config.Backend. GIF, TIFF, BMP images will be read, but saved as PNG.
func NewImageFromURL ¶
NewImageFromURL creates a new Image by downloading it from url. GIF, TIFF, BMP images will be read, but saved as PNG.
func (*Image) AspectRatio ¶
AspectRatio returns Width / Height
func (*Image) ContentType ¶
func (*Image) DeleteVersion ¶
func (*Image) OriginalVersion ¶
func (self *Image) OriginalVersion() *ImageVersion
func (*Image) RemoveAllRefs ¶
func (*Image) ThumbnailLinkedView ¶
func (*Image) ThumbnailView ¶
func (*Image) TitleOrFilename ¶
TitleOrFilename returns Title if not empty, or else Filename().
func (*Image) Version ¶
func (self *Image) Version(width, height int, horAlign HorAlignment, verAlign VerAlignment, grayscale bool) (im *ImageVersion, err error)
func (*Image) VersionCentered ¶
func (self *Image) VersionCentered(width, height int, grayscale bool) (im *ImageVersion, err error)
func (*Image) VersionCenteredLinkedView ¶
func (*Image) VersionCenteredView ¶
func (*Image) VersionHeight ¶
func (self *Image) VersionHeight(height int, grayscale bool) (im *ImageVersion, err error)
func (*Image) VersionHeightLinkedView ¶
func (*Image) VersionHeightView ¶
func (*Image) VersionLinkedView ¶
func (self *Image) VersionLinkedView(width, height int, horAlign HorAlignment, verAlign VerAlignment, grayscale bool, imageClass, linkClass string) (*view.Link, error)
func (*Image) VersionSourceRect ¶
func (self *Image) VersionSourceRect(sourceRect image.Rectangle, width, height int, grayscale bool, outsideColor color.Color) (im *ImageVersion, err error)
SourceRectVersion searches and returns an existing matching version, or a new one will be created and saved.
func (*Image) VersionSourceRectLinkedView ¶
func (*Image) VersionSourceRectView ¶
func (self *Image) VersionSourceRectView(sourceRect image.Rectangle, width, height int, grayscale bool, outsideColor color.Color, class string) (*view.Image, error)
//
func (*Image) VersionTouchOrigFromOutside ¶
func (self *Image) VersionTouchOrigFromOutside(width, height int, horAlign HorAlignment, verAlign VerAlignment, grayscale bool, outsideColor color.Color) (im *ImageVersion, err error)
func (*Image) VersionTouchOrigFromOutsideCentered ¶
func (*Image) VersionTouchOrigFromOutsideCenteredLinkedView ¶
func (*Image) VersionTouchOrigFromOutsideCenteredView ¶
func (*Image) VersionTouchOrigFromOutsideLinkedView ¶
func (*Image) VersionTouchOrigFromOutsideView ¶
func (*Image) VersionView ¶
func (self *Image) VersionView(width, height int, horAlign HorAlignment, verAlign VerAlignment, grayscale bool, class string) (*view.Image, error)
func (*Image) VersionWidth ¶
func (self *Image) VersionWidth(width int, grayscale bool) (im *ImageVersion, err error)
func (*Image) VersionWidthLinkedView ¶
func (*Image) VersionWidthView ¶
type ImageRef ¶
type ImageRef string
func NewImageRef ¶
func (*ImageRef) OriginalVersion ¶
func (self *ImageRef) OriginalVersion() (*ImageVersion, error)
func (*ImageRef) OriginalVersionLinkedView ¶
func (*ImageRef) OriginalVersionView ¶
func (*ImageRef) Thumbnail ¶
func (self *ImageRef) Thumbnail(size int) (im *ImageVersion, err error)
func (*ImageRef) ThumbnailLinkedView ¶
func (*ImageRef) ThumbnailView ¶
func (*ImageRef) Version ¶
func (self *ImageRef) Version(width, height int, horAlign HorAlignment, verAlign VerAlignment, grayscale bool) (im *ImageVersion, err error)
func (*ImageRef) VersionCentered ¶
func (self *ImageRef) VersionCentered(width, height int, grayscale bool) (im *ImageVersion, err error)
func (*ImageRef) VersionCenteredLinkedView ¶
func (*ImageRef) VersionCenteredView ¶
func (*ImageRef) VersionHeight ¶
func (self *ImageRef) VersionHeight(height int, grayscale bool) (im *ImageVersion, err error)
func (*ImageRef) VersionHeightLinkedView ¶
func (*ImageRef) VersionHeightView ¶
func (*ImageRef) VersionLinkedView ¶
func (self *ImageRef) VersionLinkedView(width, height int, horAlign HorAlignment, verAlign VerAlignment, grayscale bool, imageClass, linkClass string) (*view.Link, error)
func (*ImageRef) VersionSourceRect ¶
func (*ImageRef) VersionSourceRectLinkedView ¶
func (*ImageRef) VersionSourceRectView ¶
func (*ImageRef) VersionTouchOrigFromOutside ¶
func (self *ImageRef) VersionTouchOrigFromOutside(width, height int, horAlign HorAlignment, verAlign VerAlignment, grayscale bool, outsideColor color.Color) (im *ImageVersion, err error)
func (*ImageRef) VersionTouchOrigFromOutsideCentered ¶
func (*ImageRef) VersionTouchOrigFromOutsideCenteredLinkedView ¶
func (*ImageRef) VersionTouchOrigFromOutsideCenteredView ¶
func (*ImageRef) VersionTouchOrigFromOutsideLinkedView ¶
func (*ImageRef) VersionTouchOrigFromOutsideView ¶
func (*ImageRef) VersionView ¶
func (self *ImageRef) VersionView(width, height int, horAlign HorAlignment, verAlign VerAlignment, grayscale bool, class string) (*view.Image, error)
func (*ImageRef) VersionWidth ¶
func (self *ImageRef) VersionWidth(width int, grayscale bool) (im *ImageVersion, err error)
func (*ImageRef) VersionWidthLinkedView ¶
type ImageRefController ¶
type ImageRefController struct {
view.SetModelValueControllerBase
}
type ImageVersion ¶
type ImageVersion struct { ID model.String `bson:",omitempty"` Filename model.String ContentType model.String SourceRect ModelRect OutsideColor model.Color Width model.Int Height model.Int Grayscale model.Bool // contains filtered or unexported fields }
func (*ImageVersion) AspectRatio ¶
func (self *ImageVersion) AspectRatio() float64
AspectRatio returns Width / Height
func (*ImageVersion) GetURL ¶
func (self *ImageVersion) GetURL() view.URL
func (*ImageVersion) LinkedView ¶
func (self *ImageVersion) LinkedView(imageClass, linkClass string) *view.Link
func (*ImageVersion) SaveImageData ¶
func (self *ImageVersion) SaveImageData(data []byte) error