// TODO: this can be optimized significantly.......... // Ping / DecodeConfig ... do we have to use image magick.......? func GetImageInfo(ctx context.Context, w http.ResponseWriter, r *http.Request) { url := r.URL.Query().Get("url") if url == "" { respond.ApiError(w, 422, errors.New("no image url")) return } response, err := app.Fetcher.Get(ctx, url) if err != nil { respond.ApiError(w, 422, err) return } data := response.Data ng := imagick.Engine{} imfo, err := ng.GetImageInfo(data) if err != nil { respond.ApiError(w, 422, err) return } imfo.URL = response.URL.String() imfo.Mimetype = MimeTypes[imfo.Format] w.Header().Set("X-Meta-Width", fmt.Sprintf("%d", imfo.Width)) w.Header().Set("X-Meta-Height", fmt.Sprintf("%d", imfo.Height)) w.Header().Set("Cache-Control", fmt.Sprintf("public, max-age=%d", app.Config.CacheMaxAge)) respond.JSON(w, 200, imfo) }
func (im *Image) LoadImage() (err error) { defer metrics.MeasureSince([]string{"fn.image.LoadImage"}, time.Now()) // TODO: throttle the number of images we load at a given time.. // this should be configurable... defer func() { if r := recover(); r != nil { var ok bool err, ok = r.(error) if !ok { err = fmt.Errorf("imgry: %v", r) } } }() var formatHint string if im.SrcFileExtension() == "ico" { formatHint = "ico" } ng := imagick.Engine{} im.img, err = ng.LoadBlob(im.Data, formatHint) if err != nil { if err == imagick.ErrEngineFailure { lg.Fatalf("**** ENGINE FAILURE on %s", im.SrcUrl) } return err } im.sync() return nil }