dryl34156 2017-12-10 19:56
浏览 47
已采纳

无法在图像代理上调整图像大小

I am trying to integrate github.com/willnorris/imageproxy/ on an existing server and have the images served on "/proxy/" path. I have:

package main

import (
    "log"
    "net/http"

    "github.com/gorilla/mux"
    "willnorris.com/go/imageproxy"
)

func main() {
    p := imageproxy.NewProxy(nil, nil)

    router := mux.NewRouter()
    router.NewRoute().Name("proxy").Methods("GET").PathPrefix("/proxy/").Handler(http.StripPrefix("/proxy/", p))

    server := &http.Server{
        Addr:    ":8000",
        Handler: router,
    }

    //server.Handler = p

    log.Printf("Listening at %v", server.Addr)
    log.Fatal(server.ListenAndServe())
}

When I try to resize an image, the first digit seems to get cutoff: http://127.0.0.1:8000/proxy/250x,/https:/octodex.github.com/images/codercat.jpg

returns a 50x50 image rather than a 250x250 image.

A 250x250 image is accessable by http://127.0.0.1:8000/proxy/2250x,/https:/octodex.github.com/images/codercat.jpg

Uncommenting server.Handler = p works and images are resized as expected.

展开全部

  • 写回答

1条回答 默认 最新

  • douwen8424 2017-12-10 21:33
    关注

    Use http.StripPrefix to remove "/proxy" from the request path before invoking the image proxy handler. Note that there's not a trailing / on the first argument to StripPrefix.

    router.NewRoute().Name("proxy").Methods("GET").PathPrefix("/proxy/").Handler(http.StripPrefix("/proxy", p))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部