func (pr *BimgProcessor) Process(buffer []byte, geo btcdn.GeoBox) (img btcdn.Image, err error) { bimgImg := bimg.NewImage(buffer) var newImage []byte gravity := resolveGravity(geo.Gravity()) if geo.Cropped() && geo.Resized() { newImage, err = resizeAndCrop(bimgImg, geo.Width(), geo.Height(), gravity) } else if geo.Resized() { if geo.Mode() == "!" { newImage, err = forceResize(bimgImg, geo.Width(), geo.Height()) } else { newImage, err = resize(bimgImg, geo.Width()) } } else if geo.Cropped() { newImage, err = crop(bimgImg, int(float64(geo.Offset()[1])), int(float64(geo.Offset()[0])), geo.Width(), geo.Height()) } if geo.Greyscale() { newImage, err = bimgImg.Colourspace(bimg.INTERPRETATION_B_W) } img = &Image{ body: newImage, mime: Mimes[bimgImg.Type()], } return }
func resizeWithLib(sourceFile string, destinationFile string, width int, height int) error { options := bimg.Options{ Width: width, Height: height, Crop: true, Quality: 90, Interlace: true, } buffer, err := bimg.Read(sourceFile) if err != nil { return err } newImage, err := bimg.NewImage(buffer).Process(options) if err != nil { return err } err = bimg.Write(destinationFile, newImage) if err != nil { return err } return nil }