Example #1
0
// Fill Photo with AlbumId, Filename, CreatedAt, Sizes and resize images
func FillPhoto(a *model.Album, p *model.Photo, photoNum int) {
	p.Filename = model.PhotoName(photoNum)
	p.CreatedAt = time.Now()
	p.AlbumId = a.AlbumId

	x, json, _ := ReadExif(a.PathSource() + p.OriginalName)
	p.EXIF = json

	if x != nil {
		if date, err := x.Get("DateTimeOriginal"); err == nil {
			p.PhotoDate, err = time.Parse("2006:01:02 15:04:05", date.StringVal())
		}
	}
}
Example #2
0
// Create HD and Thumbs Photos
func CreatePhotos(a *model.Album, p *model.Photo) (err error) {
	src, err := imaging.Open(a.PathSource() + p.OriginalName)
	if err != nil {
		return err
	}

	var dst *image.NRGBA
	filename := a.PathHD() + p.Filename
	log.Printf("Saving HD: %s\n", filename)
	dst = imaging.Fit(src, cfg.Image.MaxWidth, cfg.Image.MaxHeight, imaging.Lanczos)
	size, err := rewriteImage(dst, filename)
	if err != nil {
		return err
	}

	p.FileSizeHD = size
	filename = a.PathThumbs() + p.Filename
	log.Printf("Saving Thumb: %s\n", filename)
	dst = imaging.Thumbnail(dst, cfg.Image.ThumbWidth, cfg.Image.ThumbHeight, imaging.CatmullRom) // resize and crop the image to make a 200x200 thumbnail
	_, err = rewriteImage(dst, filename)

	return err
}