GithubHelp home page GithubHelp logo

imageoptimizer's Introduction

Image Optimizer for Visual Studio

Build status

Download this extension from the VS marketplace Visual Studio 2017, 2019 or Visual Studio 2022 or get the nightly build.


Uses industry standard tools to optimize any JPEG, PNG and Gifs - including animated Gifs. It can do both lossy and lossless optimization.

Features

Adds a right-click menu to any folder and image in Solution Explorer that let's you automatically optimize all PNG, GIF and JPEG files in that folder.

  • Optimizes PNGs (uses Zopfli compression)
  • Optimizes GIFs
  • Optimizes animated GIFs
  • Optimizes JPGs (uses MozJPEG)
  • Works on single images files or entire folders
  • Copy any image as base64 dataURI to clipboard

Optimize images

Simply right-click any file or folder containing images and click one of the image optimization buttons.

Context menu

You can also right-click a folder to optimize all images inside it.

Best quality

If you chose best quality optimization, the tool will do its optimizations without changing the quality of the image.

Best compression

If you decide to sacrifice just a small amount of image quality (which in most cases is unnoticeable to the human eye), you will be able to save up to 90% of the initial file weight. Lossy optimization will give you outstanding results with just a fraction of image quality loss.

Output window

The Output Window shows the detailed output from the optimization process and progress is displayed in the status bar.

Output window

Performance

Optimizing an image can easily take several seconds which feels slow. This extension parallelizes the workload on each CPU core available on the machine. This speeds up the optimization significantly.

API for extenders

Any extension can call the commands provided in the Image Optimizer extension to optimize any image.

public void OptimizeImage(string filePath)
{
	try
	{
		var DTE = (DTE2)Package.GetGlobalService(typeof(DTE));
		Command command = DTE.Commands.Item("ImageOptimizer.OptimizeLossless");

		if (command != null && command.IsAvailable)
		{
			DTE.Commands.Raise(command.Guid, command.ID, filePath, null);
		}
	}
	catch (Exception ex)
	{
		// Image Optimizer not installed
	}
}

The commands are:

  • ImageOptimizer.OptimizeLossless - Optimize for best quality
  • ImageOptimizer.OptimizeLossy - Optimize for best compression

Contribute

Check out the contribution guidelines if you want to contribute to this project.

For cloning and building this project yourself, make sure to install the Extensibility Tools 2015 extension for Visual Studio which enables some features used by this project.

License

Apache 2.0

imageoptimizer's People

Contributors

al1b avatar madskristensen avatar markvantilburg avatar pjhuck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imageoptimizer's Issues

Increasing file size : optipng vs pngout

First of all thank you for ImageOptimizer !!!!

I have a lot of png's that I optimized using optipng.exe -o7 -strip all Filename.png.
Source : http://www.thewebflash.com/2014/05/how-to-optimize-jpeg-png-images-using.html

Now that you have put in all the effort to rewrite it (Thank you !) I ran it to compare the results and found this.

2015-05-04 14:50:07: Optimized confirmation.png
Before: 1341 bytes
After: 1432 bytes
Saving: -91 bytes / -6.8%

2015-05-04 14:50:07: Optimized homeLoanImage.jpg
Before: 44656 bytes
After: 44656 bytes
Saving: 0 bytes / 0%

2015-05-04 14:50:07: Optimized brochure_bathrooms.png
Before: 162 bytes
After: 212 bytes
Saving: -50 bytes / -30.9%

2015-05-04 14:50:07: Optimized brochure_bedrooms.png
Before: 160 bytes
After: 223 bytes
Saving: -63 bytes / -39.4%

2015-05-04 14:50:07: Optimized brochure_garages.png
Before: 229 bytes
After: 307 bytes
Saving: -78 bytes / -34.1%

Could you please have a look into why the image size was increased instead of reduced?
I do understand that you provide a interface and did not develop the tools : optipng vs pngout
Perhaps you can build in a check to only replace the image if the size was actually reduced ?

Visual Studio 2013 crashes System.ArgumentNullException

I rightclick a folder with a number of subfolders (589 Files, 10 Folders) that contain multiple file types and choose optimize images;

An unhandled exception of type 'System.ArgumentNullException' occurred in mscorlib.dll

Additional information: File name cannot be null.

Please add support for folder view in Visual Studio 2017

Installed product versions

  • Visual Studio: 2017 Enterprise
  • This extension: 3.6.103

Description

Right now to optimize several images I have to create a solution and project, add the images, and then run the optimizer.

Can you please add support for folder view so there is no need for a solution file?

Installation issues with V3.6.94

Installed product versions

  • Visual Studio: 2015 Pro V14.0.25431.01 Update3
  • Image Optomizer V3.6.94

Description

Trying to install VSIX and getting an error "This file is not a valid VSIX package"
Additionally when installing thru Nuget it seems to be installing but after restarting VS I'm prompted again to install Image Optimizer. This continues as many times as I care to try.

Steps to recreate

  1. Download
  2. Install

Update gifsicle to v1.95

Current version installed is:

Resources\Tools> .\gifsicle.exe --version
LCDF Gifsicle 1.92
Copyright (C) 1997-2019 Eddie Kohler

According to the website
https://www.lcdf.org/gifsicle/

There are newer versions available:

1.95 19.Feb.2024
Fix some bugs.

1.94 23.Jun.2023
Fix some bugs.

1.93 30.Jun.2021
Fix security bug on certain resize operations with ‘--resize-method=box’.
Fix problems with colormapless GIFs.

The command line parameters are still the same so this would be a simple replace of the .exe

Review count discrepancy

Installed product versions

  • Visual Studio: n/a
  • This extension: 3.6.94

Description

The 'REVIEWS' count for this extension says "(57)" but the "REVIEWS" tab says "(55)".

This may not be an issue with this specific extension, possibly an issue with the VS gallery perhaps, but I'm not sure where to log the apparent bug, so for now I'll log here but happy to move it elsewhere if appropriate.

Steps to recreate

  1. Visit https://visualstudiogallery.msdn.microsoft.com/a56eddd3-d79b-48ac-8c8f-2db06ade77c3 (in Chrome or IE11, and probably the same issue in all browsers)
  2. Check the two review counts as per screen shot below
    image

Error message shown by VS File.Copy if result wasn't created

The Saving and Percent methods on CompressionResult return bogus savings (e.g. 100%) if the result file does not exist (e.g. because a tool failed).

This causes an error upstream because HandleResult calls File.Copy method and passes it a null argument (result.ResultFileName) if the Saving property returns a value greater than 0.

Please add support for Visual Studio 2017

I want to start testing the new VS2017 at work, but it'll be harder without this awesome extension. Is there anything in the extension code that prevents it from working properly in the new Visual Studio?

Can this be used inside mvc or .net Core

hello,

i would like to know if this project can be turned into a dll to be used inside web projects. something like passing a list of file paths creating optimized images and with option[bool param] of preserving old files by renaming them to filename-old.ext to same place or provided path.

thanks

Edit: this will save a lot of round trip & ftp we need to do these days using pagespeed.

Cannot find extentions in Visual code + extension/package.json not found inside zip.

Visual Studio:
Version: 1.27.2 (user setup)
Commit: f46c4c469d6e6d8c46f268d1553c5dc4b475840f
Date: 2018-09-12T16:17:45.060Z
Electron: 2.0.7
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64

Hello,

I have 2 issues with your extenstion:

1)I cannot find it in the search extension of Visual Code(It does not exists anymore).

2)When I download it from here:
https://marketplace.visualstudio.com/items?itemName=MadsKristensen.ImageOptimizer

And try to install it via the visual code "Install from VSIX", I get this error:
"extension/package.json not found inside zip."

Any idea why please?

Thank you.

BUG: Image Optimizer menu item command missing from context menu for image file

Installed product versions

  • Microsoft Visual Studio Professional 2019 Preview Version 16.4.0 Preview 4.0
  • This extension: 4.0.132

Description

The image Optimizer context menu item command is missing when right clicking n image file

Steps to recreate

  1. Open a folder containing images (File->Open->Folder...)
  2. Right click an image in solution explorer
  3. The "Image Optimizer" command is missing from the context menu.

image

Lossy Optimization Issue

Installed product versions

  • Visual Studio 2015 Professional Update 2
  • Image Optimizer 3.5.80

Description

Lossy optimization of an image of clouds resulted in some strange results (see attached zip).

Steps to recreate

  1. Use Image Optimizer in VS 2015 Pro to "lossy optimize" clouds-original.jpg.

Current behavior

clouds-lossy.jpg contains strange visible bands.

Expected behavior

Image should look similar to clouds-original.jpg.

clouds.zip

No lossless/lossy options on context menu

Installed product versions

  • Visual Studio: 2015 Enterprise Update 1
  • This extension: 3.4.60

Description

There is no "Image optimizer" context menu option and the "Optimize image" one doesn't show the lossless/lossy options

Steps to recreate

  1. Richt-Click an image file from solution explorer
  2. Hover on the "Optimize image" context menu option

Current behavior

Image optimizer doesn't show the lossless/lossy context menu options

Expected behavior

Show the lossless/lossy context menu options

Screenshot

optimizeimage

DPI values are lost after optimization

Description

All optimizations on the image reset the dpi. But it very important to keep the original value, because it will be used in WPF

Steps to recreate

  1. Get jpeg/png file with custom DPI values
  2. Optimize

Current behavior

The DPI value is lost or set to default 96 dpi.

Expected behavior

The DPI value keep original value

Installation issue against VS 2017 RC

Installed product versions

  • Visual Studio 2017 RC Professional
  • This extension: 3.6.103

Description

I installed this extension for 2013 and 2015, but it does not recognize 2017 RC as a possible install target.

Current behavior

Will not install to 2017

Expected behavior

Should be able to install to the VS 2017 Professional RC.

extension/package.json not found inside zip.

Installed product versions

$code --install-extension Image_Optimizer_v4.0.132.vsix
Installing extensions...
extension/package.json not found inside zip.
Failed Installing Extensions: Image_Optimizer_v4.0.132.vsix

Version: 1.47.3
Commit: 91899dcef7b8110878ea59626991a18c8a6a1b3e
Date: 2020-07-23T15:51:39.791Z
Electron: 7.3.2
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Linux x64 5.4.0-42-generic snap

Here's a screen grab.
https://i.imgur.com/NxFniKu.png
There are 2 json. Maybe the bug is on Version: 1.47.3

I tried with another app and got the same error.

The 'ImageOptimizer' package did not load correctly

Installed product versions

  • Visual Studio: 2013 Ultimate
  • This extension: 3.6.92

Description

When opening a solution in Visual Studio 2013 I am presented with the dreaded The 'ImageOptimizer' package did not load correctly. error message.

Steps to recreate

  1. Install the VSIX
  2. Open an existing solution

Current behavior

When opening a solution in Visual Studio 2013 I am presented with the dreaded The 'ImageOptimizer' package did not load correctly. error message.

The ActivityLog.xml file contains the following entries:

<entry>
    <record>770</record>
    <time>2016/08/01 14:52:36.572</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>CreateInstance failed for package [ImageOptimizerPackage]</description>
    <guid>{BF95754F-93D3-42FF-BFE3-E05D23188B08}</guid>
    <hr>80070002</hr>
    <errorinfo>Could not load file or assembly 'Microsoft.VisualStudio.Shell.11.0, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.</errorinfo>
  </entry>
  <entry>
    <record>771</record>
    <time>2016/08/01 14:52:36.572</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>End package load [ImageOptimizerPackage]</description>
    <guid>{BF95754F-93D3-42FF-BFE3-E05D23188B08}</guid>
    <hr>80004005 - E_FAIL</hr>
    <errorinfo>Could not load file or assembly 'Microsoft.VisualStudio.Shell.11.0, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.</errorinfo>
  </entry>

Expected behavior

Solution opens and package loads properly

Use Google guetzli instead of jpegtran

Installed product versions

  • Visual Studio: 2017 Community
  • This extension: 3.6.103

Description

ImageOptimizer is using jpegtran for lossless compression of JPEG images. It's been a while Google has released it's Perceptual JPEG encoder guetzli. The result of guetzli is really better than other compressors. As it says it could compress to 35% more than the other compressors.

Lossy optimize image removed all image bytes (Saving 100%)

Hi @madskristensen
Thanks for the awesome extensions you create that saves huge time.
I'm using these extensions from the very first version you introduced years back but today I noticed 100% saving on JPG image and turned file size 0. As usual, I right clicked on 'images' folder | Image Optimizer | Lossy Optimize Images. Here's the output in Visual Studio 2015 Update 3:

100-percent-saved

In case you need the image file, here's the one:

course_thumbnail_default

HiDPI PNGs are damaged

pngout is run with parameters that strip the pHYs chunk that declares the image's resolution. This causes behavioral changes for images at non-default resolutions (e.g. 300dpi "Retina" images).

This is a common bug in image optimizer tools; e.g. google/zopfli#43

Some .gif images crash ImageOptimizer

Upgraded to ImageOptimizer 3.0.15. Seems to work fine on .png and .jpg images. But when it tries to optimize some of my .gif images, it crashes with Event ID 1026. Some .gif images are optimized ok, so it's only certain .gif images that have this problem.

Application: devenv.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentNullException
Stack:
at System.IO.File.Copy(System.String, System.String, Boolean)
at MadsKristensen.ImageOptimizer.ImageOptimizerPackage.HandleResult(MadsKristensen.ImageOptimizer.CompressionResult, Int32)
at MadsKristensen.ImageOptimizer.ImageOptimizerPackage+<>c__DisplayClass3.b__2(System.Object)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

VS Code Support

I would Love to have this tool in VS Code.
I have been debating trying to write my own but love ImageOptimizer.

Summary of operation

This tool is great :) thanks for working on this. I do have one request though, currently it shows detailed output which is great but it would be also helpful if there is one line summary of the operation.

For example:
Optimized X images, total bytes saved Y
where:
X is count
Y can be bytes/kb/mb based on the number of bytes

Update
I take this back, I just noticed method DisplayEndResult in https://github.com/madskristensen/ImageOptimizer/blob/master/src/ImageOptimizerPackage.cs, I am not sure then why it didn't render this information inside Output window.

Extension causes 10-15 second lock up on solution context menu

Installed product versions

  • Visual Studio: 2015 Professional 14.0.25422.01 Update 3
  • Image Optimizer 3.6.89 (installed with the web extension pack)

Description

Visual studio hangs (often with 'not responding' at the top of the window) for 10-15 seconds on the right-click context menu in solution explorer and 15-20 seconds on the 'Image optimizer' menu. It is a very large solution with a lot of projects (not sure if that's related to the amount of delay).

Steps to recreate

  1. Enable the 'Image Optimizer' extension.
  2. Right click on the solution in solution explorer.
  3. After recoving from the initial 10-15 second hang with VS not responding, if you go to the 'Image optimizer' context menu item, it also hangs if you click this item for 15-20 seconds before the sub menu appears.

Current behavior

Visual studio now hangs (often with 'not responding' at the top of the window) for 10-15 seconds on solution explorer context menu and 15-20 seconds on the 'Image optimizer' menu as described above.

Expected behavior

Not hanging, context menu loads instantaneously with no delay after right click.

No longer present in menu since VS 2017 since 15.6.4 update

VS 2017 15.6.4
Installed via Web Essentials 2017 package

The option to optimize images is no longer present in the menu when right clicking an image. I didn't really pay attention as to exactly when it vanished but the only thing that has changed recently is the 15.6.4 update. This is with a Core 2.0 MVC project open.

Extension doesn't work in Visual Studio 2012

Tried installing the latest version of the Image Optimizer (3.0.24) in to my Visual Studio 2012 (Version 11.0.61030.00 Update 4).

After restarting, a message was displayed stating that the Package did not load correctly.
It stated more information could be found in the Activity Log.

Looking into it, the following entry was added to the Activity Log:

  <entry>
    <record>523</record>
    <time>2015/05/05 13:12:16.814</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>End package load [ImageOptimizerPackage]</description>
    <guid>{BF95754F-93D3-42FF-BFE3-E05D23188B08}</guid>
    <hr>80004005 - E_FAIL</hr>
    <errorinfo>Could not load file or assembly 'Microsoft.VisualStudio.Shell.12.0, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.</errorinfo>
  </entry>

PS: I've used your extension for years and loved it. Hopefully I be able to continue using it!

How to use this with VS 2022

Installed product versions

Could not install in VS 2022

Description

I would like to uses the ImageOptimizer in VS 2022

Steps to recreate

  1. I downloaded the installer

Current behavior

It says: "Install with VS 2019"

Expected behavior

"Install with VS 2022"

#ask: this project can't open on vs2013

Hi

I'v working on vs 2013, So this project cann't open ???

When I read
"For cloning and building this project yourself, make sure to install the Extensibility Tools 2015 extension for Visual Studio which enables some features used by this project."

That's meen we need install Extensibility Tools 2015

Tks

"Optimize image" context menu option causing a fatal error

Installed product versions

  • Visual Studio: 2015 Enterprise Update 1
  • This extension: 3.4.60

Description

Each time i try to optimize an image, Visual Studio crashes and I get the following error messages on Event Viewer:

crash

eventviewer1

eventviewer2

### Steps to recreate 1. Right-Click an image on Solution Explorer 2. Select the "Optimize image" context menu option ### Current behavior

Visual Studio crashes and errors are being registered on Event Viewer:

Expected behavior

Optimize the image and show the detailed output from the optimization process

imaging

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Chocolatey Install Issue - No CheckSum by default

Installed product versions

  • Powershell
  • Chocolatey v.0.10.13

Description

Trying to install this package using Chocolatey and getting an error because there is no checksum value by default. It is erroring out saying that 'Empty checksums are no longer allowed by default for non-secure sources.' Would prefer to not use the --allow-empty-checksums command without needing too.

Steps to recreate

  1. Open powershell
  2. Install chocolatey
  3. choco install imageoptimizer

Images inside Resource file

Installed product versions

  • Visual Studio Professional 2017 15.7.4
  • This extension: 4.0.131

Description

Add ability to process images in resource files (*.resx)

Steps to recreate

  1. Open Winforms Project
  2. Solution Explorer
  3. Right click resx file (with images inside)
  4. Image optimizer > Optimize for Best [...]

Current behavior

No images found to optimize

Expected behavior

  • Extract images from resx file
  • Compress images
  • Replace previous images inside resx file

Compile error after recent changes

Installed product versions

  • Visual Studio: 2019 Professional

Description

I'm often using ImageOptimizer as inspiration for writing my own extension. It's a great resource for looking through code, debugging a running extension, etc. But after recent changes (maybe after VS2022) support I can no longer compile the extension through Visual Studio. I'm getting the following error:

Unable to locate the extensions directory. "Could not load file or assembly 'Microsoft.VisualStudio.Validation, Version=16.10.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.".

The extension compiles without any problems with MSBuild from the command-line (same command as in the appveyor config). But being able to compile this from VS makes it a lot easier to debug the extension.

Do you know what is going on there?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.