Example #1
0
// Create a new blob object from an existing size
func (im *Image) MakeSize(sizing *imgry.Sizing) (*Image, error) {
	defer metrics.MeasureSince([]string{"fn.image.MakeSize"}, time.Now())

	if err := im.ValidateKey(); err != nil {
		return nil, err
	}

	im2 := &Image{
		Key:         im.Key,
		Data:        im.Data,
		SrcUrl:      im.SrcUrl,
		Sizing:      sizing,
		SizingQuery: sizing.ToQuery().Encode(),
	}

	// Clone the originating image
	var err error

	if err = im2.LoadImage(); err != nil {
		return nil, err
	}

	// Resize the new image object
	if err = im2.SizeIt(sizing); err != nil {
		return nil, err
	}

	return im2, nil
}
Example #2
0
func (b *Bucket) DbIndexKey(imageKey string, optSizing ...*imgry.Sizing) string {
	var sizing *imgry.Sizing
	if len(optSizing) > 0 { // sizing is optional
		sizing = optSizing[0]
	}
	key := fmt.Sprintf("%s/%s", b.ID, imageKey)
	if sizing != nil {
		key = fmt.Sprintf("%s:q/%s", key, sha1Hash(sizing.ToQuery().Encode()))
	}
	return key
}