本文整理汇总了Golang中image.DecodeConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang DecodeConfig函数的具体用法?Golang DecodeConfig怎么用?Golang DecodeConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DecodeConfig函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: decode
// decoder reads an image from r and modifies the image as defined by opts.
// swapDimensions indicates the decoded image will be rotated after being
// returned, and when interpreting opts, the post-rotation dimensions should
// be considered.
// The decoded image is returned in im. The registered name of the decoder
// used is returned in format. If the image was not successfully decoded, err
// will be non-nil. If the decoded image was made smaller, needRescale will
// be true.
func decode(r io.Reader, opts *DecodeOpts, swapDimensions bool) (im image.Image, format string, err error, needRescale bool) {
if opts == nil {
// Fall-back to normal decode.
im, format, err = image.Decode(r)
return im, format, err, false
}
var buf bytes.Buffer
tr := io.TeeReader(r, &buf)
ic, format, err := image.DecodeConfig(tr)
if err != nil {
return nil, "", err, false
}
mr := io.MultiReader(&buf, r)
b := image.Rect(0, 0, ic.Width, ic.Height)
sw, sh, needRescale := opts.rescaleDimensions(b, swapDimensions)
if !needRescale {
im, format, err = image.Decode(mr)
return im, format, err, false
}
imageDebug(fmt.Sprintf("Resizing from %dx%d -> %dx%d", ic.Width, ic.Height, sw, sh))
if format == "cr2" {
// Replace mr with an io.Reader to the JPEG thumbnail embedded in a
// CR2 image.
if mr, err = cr2.NewReader(mr); err != nil {
return nil, "", err, false
}
format = "jpeg"
}
if format == "jpeg" && fastjpeg.Available() {
factor := fastjpeg.Factor(ic.Width, ic.Height, sw, sh)
if factor > 1 {
var buf bytes.Buffer
tr := io.TeeReader(mr, &buf)
im, err = fastjpeg.DecodeDownsample(tr, factor)
switch err.(type) {
case fastjpeg.DjpegFailedError:
log.Printf("Retrying with jpeg.Decode, because djpeg failed with: %v", err)
im, err = jpeg.Decode(io.MultiReader(&buf, mr))
case nil:
// fallthrough to rescale() below.
default:
return nil, format, err, false
}
return rescale(im, sw, sh), format, err, true
}
}
// Fall-back to normal decode.
im, format, err = image.Decode(mr)
if err != nil {
return nil, "", err, false
}
return rescale(im, sw, sh), format, err, needRescale
}
开发者ID:rfistman,项目名称:camlistore,代码行数:66,代码来源:images.go
示例2: DescribeImage
func DescribeImage(uri string) (mediatype string, width, height int, filelength int64, err error) {
c := curler{
dial_timeo: connection_speedup_timeout,
}
resp, err := c.do_get(uri, nil)
if err != nil {
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
filelength = int64(-resp.StatusCode)
err = fmt.Errorf("%v: %v", resp.StatusCode, http.StatusText(resp.StatusCode))
return
}
filelength = resp.ContentLength // -1 means unknown
if filelength < 16 && filelength >= 0 {
err = fmt.Errorf("%v: %v", filelength, "content-length insufficient info")
return
}
ct := resp.Header.Get("Content-Type")
mediatype, _, _ = mime.ParseMediaType(ct)
types := strings.Split(mediatype, "/")
if types[0] != "image" {
err = fmt.Errorf("%v: unknown mime %v", uri, mediatype)
return
}
ic, mediatype, err := image.DecodeConfig(resp.Body)
width = ic.Width
height = ic.Height
return
}
开发者ID:heartszhang,项目名称:famous,代码行数:31,代码来源:imagedesc.go
示例3: parseImg
func parseImg(raw []byte) (imgInfo, error) {
//fmt.Printf("----------\n")
var info imgInfo
imgConfig, formatname, err := image.DecodeConfig(bytes.NewBuffer(raw))
if err != nil {
return info, err
}
info.formatName = formatname
if formatname == "jpeg" {
err = parseImgJpg(&info, imgConfig)
if err != nil {
return info, err
}
info.data = raw
} else if formatname == "png" {
err = paesePng(raw, &info, imgConfig)
if err != nil {
return info, err
}
}
//fmt.Printf("%#v\n", info)
return info, nil
}
开发者ID:CowLeo,项目名称:gopdf,代码行数:27,代码来源:image_obj_parse.go
示例4: TestProc
func TestProc(t *testing.T) {
cases := map[*Options]*expected{
&Options{
Format: "jpg",
Quality: 80,
Method: 3,
Base: Construct(new(Source), "http://"+test_server+"/"+file_name).(*Source),
Scale: Construct(new(Scale), "100x").(*Scale),
}: &expected{Size: &PixelDim{100, 75}, ImgType: "jpeg"},
&Options{
Format: "jpg",
Quality: 80,
Base: Construct(new(Source), "http://"+test_server+"/"+file_name).(*Source),
CropRoi: Construct(new(Roi), "1,1,500,500").(*Roi),
Scale: nil,
}: &expected{&PixelDim{500, 500}, "jpeg"},
&Options{
Format: "jpg",
Quality: 80,
Method: 3,
Base: Construct(new(Source), "http://"+test_server+"/"+file_name).(*Source),
Scale: Construct(new(Scale), "100x").(*Scale),
CropRoi: Construct(new(Roi), "center,500,500").(*Roi),
}: &expected{&PixelDim{100, 100}, "jpeg"},
&Options{
Format: "png",
Method: 3,
Base: Construct(new(Source), "http://"+test_server+"/"+file_name).(*Source),
Scale: Construct(new(Scale), "100x").(*Scale),
}: &expected{&PixelDim{100, 75}, "png"},
&Options{
Format: "png",
Method: 3,
Base: Construct(new(Source), "http://"+test_server+"/"+file_name).(*Source),
}: &expected{&PixelDim{1024, 768}, "png"},
}
for option, want := range cases {
b := Do(option)
if b == nil {
t.Errorf("Expected data, result is nil\n")
}
cfg, imgType, err := image.DecodeConfig(bytes.NewReader(b))
if err != nil {
t.Error(err)
}
resultSize := &PixelDim{cfg.Width, cfg.Height}
if !reflect.DeepEqual(resultSize, want.Size) {
t.Errorf("Expected size is %v, got %v\n", want.Size, resultSize)
}
if imgType != want.ImgType {
t.Errorf("Expected image type is %v, got %v", want.ImgType, imgType)
}
}
}
开发者ID:gnanderson,项目名称:imagio,代码行数:60,代码来源:imgproc_test.go
示例5: Config
func (m *markedImage) Config() (image.Config, error) {
cfg, _, err := image.DecodeConfig(bytes.NewReader(m.Img))
if err != nil {
return image.Config{}, e.New(err)
}
return cfg, nil
}
开发者ID:fcavani,项目名称:image,代码行数:7,代码来源:watermark.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng