/// <summary> /// Upload image to Way2enjoy and attempt to shrink it, lossless. /// </summary> /// <param name="inputFile">File to upload.</param> /// <param name="outputFile">Filename to save to.</param> /// <param name="store">Amazon S3 credentials and information.</param> /// <returns>JSON with info about the upload/shrink.</returns> public Way2enjoyResponse Shrink(string inputFile, string outputFile = null, Way2enjoyOptionsStore store = null) { var response = new JavaScriptSerializer() .Deserialize <Way2enjoyResponse>( getResponse(request(binaryFile: inputFile))); if (outputFile == null || response.output == null || string.IsNullOrEmpty(response.output.url)) { return(response); } if (store != null) { executeOption( response, null, null, null, null, store); } var webClient = new WebClient(); webClient.DownloadFile( response.output.url, outputFile); return(response); }
/// <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(Way2enjoyResponse response, int width, int height, string outputFile = null, Way2enjoyOptionsStore store = null) { return(executeOption(response, width, height, "scale", 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(Way2enjoyResponse response, int?width, int?height, string method = null, string outputFile = null, Way2enjoyOptionsStore store = null) { var options = new Way2enjoyOptions(); if (method != null && (width.HasValue || height.HasValue)) { options.resize = new Way2enjoyOptionsResize { 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); }