/// <summary> /// Execute a set of options against a previous uploaded/shrinked file. /// </summary> /// <param name="response">Response object from a upload/shrink operation.</param> /// <param name="width">Width to scale within.</param> /// <param name="height">Height to scale within.</param> /// <param name="method">Scale method to apply.</param> /// <param name="outputFile">Filename to save to.</param> /// <param name="store">Amazon S3 credentials and information.</param> /// <returns>Stream</returns> private Stream executeOption(TinifyResponse response, int?width, int?height, string method = null, string outputFile = null, TinifyOptionsStore store = null) { var options = new TinifyOptions(); if (method != null && (width.HasValue || height.HasValue)) { options.resize = new TinifyOptionsResize { method = method }; if (width.HasValue) { options.resize.width = width.Value; } if (height.HasValue) { options.resize.height = height.Value; } } if (store != null) { options.store = store; } var stream = request( "POST", response.output.url, null, options); writeStreamToDisk( stream, outputFile); return(stream); }
/// <summary> /// Scales the image down proportionally so that it fits within the given dimensions. You must provide both a width and a height. /// </summary> /// <param name="response">Response object from a upload/shrink operation.</param> /// <param name="width">Width to scale within.</param> /// <param name="height">Height to scale within.</param> /// <param name="outputFile">Filename to save to.</param> /// <param name="store">Amazon S3 credentials and information.</param> /// <returns>Stream</returns> public Stream Fit(TinifyResponse response, int width, int height, string outputFile = null, TinifyOptionsStore store = null) { return executeOption(response, width, height, "fit", outputFile, store); }
/// <summary> /// Execute a set of options against a previous uploaded/shrinked file. /// </summary> /// <param name="response">Response object from a upload/shrink operation.</param> /// <param name="width">Width to scale within.</param> /// <param name="height">Height to scale within.</param> /// <param name="method">Scale method to apply.</param> /// <param name="outputFile">Filename to save to.</param> /// <param name="store">Amazon S3 credentials and information.</param> /// <returns>Stream</returns> private Stream executeOption(TinifyResponse response, int? width, int? height, string method = null, string outputFile = null, TinifyOptionsStore store = null) { var options = new TinifyOptions(); if (method != null && (width.HasValue || height.HasValue)) { options.resize = new TinifyOptionsResize { method = method }; if (width.HasValue) options.resize.width = width.Value; if (height.HasValue) options.resize.height = height.Value; } if (store != null) options.store = store; var stream = request( "POST", response.output.url, null, options); writeStreamToDisk( stream, outputFile); return stream; }
/// <summary> /// Scales the image down proportionally. You must provide either a target width or a target height, but not both. /// </summary> /// <param name="response">Response object from a upload/shrink operation.</param> /// <param name="width">Width to scale within.</param> /// <param name="height">Height to scale within.</param> /// <param name="outputFile">Filename to save to.</param> /// <param name="store">Amazon S3 credentials and information.</param> /// <returns>Stream</returns> public Stream Scale(TinifyResponse response, int width, int height, string outputFile = null, TinifyOptionsStore store = null) { return(executeOption(response, width, height, "scale", outputFile, store)); }