Exemple #1
0
 /// <summary>
 /// Creates a new ThumborImage which uses the provided parameters to create either a
 /// signed or unsigned URL with filters and other thumbor options
 /// </summary>
 /// <param name="thumborSigner">Implementation of IThumborSigner for signing keys</param>
 /// <param name="thumborServerUrl">URL to the thumbor server EG http://mythumborserver.com/ </param>
 /// <param name="thumborSecretKey">The secret key used by the thumbor server for signing URL's</param>
 /// <param name="imageUrl">URL to the image that will be manipulated by Thumbor</param>
 public ThumborImage(ThumborSigner thumborSigner, Uri thumborServerUrl, string thumborSecretKey, string imageUrl)
 {
     this.imageUrl         = imageUrl;
     this.thumborSigner    = thumborSigner;
     this.thumborSecretKey = thumborSecretKey;
     this.thumborServerUrl = thumborServerUrl;
 }
Exemple #2
0
        /// <summary>
        /// Given pregenerated thumbor image parameters return URL to the image with signed key if one exists.
        /// NB should not include the leading /
        /// </summary>
        /// <param name="imageUrl">The image to produce the URL for EG. trim/100x200/filters:grayscale()/http://myserver/myimage.jpg </param>
        /// <returns>String containing the URL with the signed image.</returns>
        public string BuildSignedUrl(string imageUrl)
        {
            if (string.IsNullOrEmpty(this.thumborSecretKey))
            {
                return(string.Format("{0}unsafe{1}", this.thumborServerUrl, imageUrl));
            }

            var thumborSigner = new ThumborSigner();
            var signedKey     = thumborSigner.Encode(imageUrl, this.thumborSecretKey);

            return(string.Format("/{0}/{1}", signedKey, imageUrl));
        }