Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | List of all members
pagespeed::image_compression::ImageOptimizer Class Reference

#include "image_optimizer.h"

Public Member Functions

 ImageOptimizer (net_instaweb::MessageHandler *message_handler)
 
bool Optimize (StringPiece original_contents, GoogleString *optimized_contents, ImageFormat *optimized_format)
 
void set_options (const pagespeed::image_compression::ImageOptions &options)
 
void set_requested_dimension (const pagespeed::image_compression::ImageDimensions &requested_dimensions)
 
int optimized_width ()
 
int optimized_height ()
 
void set_timer (net_instaweb::Timer *timer)
 Timer and was_timed_out only apply to WebP images.
 
bool was_timed_out () const
 
bool UsesLossyFormat () const
 

Detailed Description

Optimizes an image. The supported formats include GIF (both single-frame and animated), PNG, and JPEG. They can be converted to PNG, JPEG, or WebP (including lossy, lossless, or animated WebP). They can be resized to smaller dimensions. You specify the allowed options and the requested dimensions, and the method returns the format, dimensions, and contents for the actual output.

If you specify a timer and the max_timeout_ms parameter, the method applies them to WebP images (other images are not affected by these parameters).

This class can only be used to optimize one image, i.e., an ImageOptimizer object can only have the Optimize method called once.

Member Function Documentation

bool pagespeed::image_compression::ImageOptimizer::Optimize ( StringPiece  original_contents,
GoogleString optimized_contents,
ImageFormat *  optimized_format 
)

Applies all optimizations, for example, removing metadata, reducing chroma sampling, and reducing dimension, to the image.

Todo:
TODO(huibao): Instead of buffering the optimized image contents in a string let the Optimize method take a writer and stream the contents to the output directly.
int pagespeed::image_compression::ImageOptimizer::optimized_width ( )
inline

Returns the actual dimensions of the optimized image, even when the image is not resized.

void pagespeed::image_compression::ImageOptimizer::set_requested_dimension ( const pagespeed::image_compression::ImageDimensions &  requested_dimensions)
inline

Specifies the dimensions for resizing the image to. This parameter only applies to single-frame images. You can specify either width or height, or both. If you specify only one dimension, the image will be resized with the original aspect ratio. If the dimensions cannot be honored, the image can still be optimized in other ways. You can get the actual dimension of the optimized image by using the OutputDimension method.

bool pagespeed::image_compression::ImageOptimizer::UsesLossyFormat ( ) const
inline

Returns whether the image was encoded in lossy format, if the optimization succeeded.


The documentation for this class was generated from the following file: