How does Google's Page Speed lossless image compression work?

后端 未结 9 616
Happy的楠姐
Happy的楠姐 2020-11-30 16:54

When you run Google\'s PageSpeed plugin for Firebug/Firefox on a website it will suggest cases where an image can be losslessly compressed, and provide a link to download th

9条回答
  •  隐瞒了意图╮
    2020-11-30 17:03

    To Replicate PageSpeed's JPG Compression Results in Windows:

    I was able to get exactly the same compression results as PageSpeed using the Windows version of jpegtran which you can get at www.jpegclub.org/jpegtran. I ran the executable using the DOS prompt (use Start > CMD). To get exactly the same file size (down to the byte) as PageSpeed compression, I specified Huffman optimization as follows:

    jpegtran -optimize source_filename.jpg output_filename.jpg
    

    For more help on compression options, at the command prompt, just type: jpegtran

    Or to Use the Auto-generated Images from the PageSpeed tab in Firebug:

    I was able to follow Pumbaa80's advice to get access to PageSpeed's optimized files. Hopefully the screenshot here provides further clarity for the FireFox environment. (But I was not able to get access to a local version of these optimized files in Chrome.)

    And to Clean up the Messy PageSpeed Filenames using Adobe Bridge & Regular Expressions:

    Although PageSpeed in FireFox was able to generate optimized image files for me, it also changed their names turning simple names like:

    nice_picture.jpg
    

    into

    nice_picture_fff5e6456e6338ee09457ead96ccb696.jpg
    

    I discovered that this seems to be a common complaint. Since I didn't want to rename all my pictures by hand, I used Adobe Bridge's Rename tool along with a Regular Expression. You could use other rename commands/tools that accept Regular Expressions, but I suspect that Adobe Bridge is readily available for most of us working with PageSpeed issues!

    1. Start Adobe Bridge
    2. Select all files (using Control A)
    3. Select Tools > Batch Rename (or Control Shift R)
    4. In the Preset field select "String Substitution". The New Filenames fields should now display “String Substitution”, followed by "Original Filename"
    5. Enable the checkbox called “Use Regular Expression”
    6. In the “Find” field, enter the Regular Expression (which will select all characters starting at the rightmost underscore separator):

      _(?!.*_)(.*)\.jpg$

    7. In the “Replace with” field, enter:

      .jpg

    8. Optionally, click the Preview button to see the proposed batch renaming results, then close

    9. Click the Rename button

    Note that after processing, Bridge deselects files that were not affected. If you want to clean all your .png files, you need reselect all the images and modify the configuration above (for "png" instead of "jpg"). You can also save the configuration above as a preset such as "Clean PageSpeed jpg Images" so that you can clean filenames quickly in future.

    Configuration Screenshot / Troubleshooting

    If you have troubles, it's possible that some browsers might not show the RegEx expression above properly (blame my escape characters) so for a screenshot of the configuration (along with these instructions), see:

    How to Use Adobe Bridge's Batch Rename tool to Clean up Optimized PageSpeed Images that have Messy Filenames

提交回复
热议问题