Scott Hanselman

Bloggers: Know when to use a JPG and when to use a PNG and always Squish them both

May 21, 2014 Comment on this post [24] Posted in Musings
Sponsored By

The best rule of thumb for bloggers using images in their posts is:

Use JPGs for photographs, landscapes, and faces. Use PNGs for charts, graphs, screenshots and cartoons. Use GIFs only for animations, and sparingly.

As with all rules of thumbs, you should use your best judgment. You should aim to understand how these two image formats work so you can make the right decision.

JPEGs

imageJPGs (JPEGs) are "lossy." That means they lose data. They literally throw image data away that they figure your eyes won't see. A good example would be a landscape with a large blue sky. The image format could hold all the detail of the blue sky, literally millions of pixels saying blue, blue, dark blue, darkish blue, sky blue...or it could say "this is a whole area of mostly blueish." Sure, some detail is lost, but for the most part, it's a big blue sky, right? When you save a JPG in your paint program (like Paint.NET) and there's a quality slider for the JPG, the lower the number the more data you'll throw away.

File from Wikimedia Commons

PNGs

PNGs are "lossless." That means that they don't lose data when they are saved. They are more like ZIP files than like JPGs. PNGs also are known for their ability to have transparent regions. With a JPG you might have a white background, but a similar PNG could have a transparent background and be overlaid on other graphics.

File from Wikimedia Commons

Regardless of which one you choose, chances are that the paint app you use (even Photoshop) haven't removed all the unneeded data from your graphics files. Applications like PNGGauntlet or PNGOut can squeeze 10, 20, even 30% from a already-saved file without any loss in quality. This is especially important given the number of folks browsing on mobile devices. Bandwidth matters, and you do everyone a disservice with every one megabyte graphics file you upload to your blog.

pnggauntlet-screen-a0eadac6[1]

I'm a huge fan of PNGGauntlet. There's also Trimage that optimizes JPGs and PNGs on Linux, and ImageOptim for Mac.

PNGGaultlet works HARD. It will turn your PCs fan on, I'm sure, as it works very hard. But PNGGauntlet tries all of PNGOUT, OptiPNG, and DeflOpt and picks the best result to create the smallest PNGs.

After you've got that blog post perfect, I recommend you add a "squish the graphics" step to your workflow. You'll only gain speed and happier readers.

Related Links


Sponsor: Many thanks to Izenda for sponsoring the blog feed this week. Please do check out their Intuitive Ad Hoc Reporting with Stunning Visualizations - Embed real time dashboards into your ASP.NET applications for easy, custom reports across all devices. Download a FREE TRIAL of Izenda Today!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

The Future of .NET on the Server: ASP.NET vNext content and videos from TechEd 2014

May 18, 2014 Comment on this post [13] Posted in ASP.NET
Sponsored By
David Fowler and Scott Hanselman on ASP.NET vNext

Hi everyone, last week we announced ASP.NET vNext to the world at TechEd North America. All the sessions videos are up and available for downloading on Channel 9! There are still many MANY months between this early alpha that we've shared and release, so I'd encourage you all to subscribe to the .NET Web Development blog. This is a group blog, from and by the ASP.NET and Azure Web Tools team. It's an excellent and unfiltered group blog that everyone contributes to. Also follow the team on Twitter @aspnet and Facebook as we post there regularly.

We also released Visual Studio 2013.2 so be sure to go get that free update.

While everyone's jazzed about ASP.NET vNext, there's a lot of cool new stuff you can do TODAY with ASP.NET, like:

OK, here's the videos from TechEd.

ASP.NET vNext Videos at TechEd

Other ASP.NET videos from TechEd

http://www.asp.net/vnext

We've also updated the ASP.NET site with all new vNext content and walkthroughs.

Thanks for reading! I hope you enjoy piling through these posts and watching these videos. We sure have had fun (and continue to!) building all this. Remember, all the code is at http://github.com/aspnet.


Sponsor: Many thanks to Izenda for sponsoring the blog feed this week! Intuitive Ad Hoc Reporting with Stunning Visualizations - Embed real time dashboards into your ASP.NET applications for easy, custom reports across all devices.Download a FREE TRIAL of Izenda Today!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Introducing ASP.NET vNext

May 12, 2014 Comment on this post [147] Posted in ASP.NET | ASP.NET MVC | ASP.NET Web API | Open Source
Sponsored By

There’s some really cool stuff going on on the ASP.NET and Web Tools team. The team has been pushing open stuff at Microsoft for a few years now and we've joined forces with the amazing innovators from the .NET core team and beyond! Some of these features are 10+ years in the making from a host of technical wizards across many teams and disciplines.

Today we’re announcing a preview (read: alpha) of the next generation of .NET on the Server.

You may have heard about some of these announcements at Build:

ASP.NET vNext will take things to the next level. Today, you run ASP.NET using the same CLR that desktop apps use. We’re adding a cloud-optimized (my cloud, your cloud, their cloud - server stuff) version optimized for server scenarios like low-memory and high-throughput.

ASP.NET vNext will let you deploy your own version of the .NET Framework on an app-by-app-basis. One app with new libraries can’t break an app next door with a different version. Different apps can even have their own cloud-optimized CLR of their own version. The CLR and cloud-optimized libraries are NuGet packages!

In this screenshot you can see build 418 and build 420 of the new framework (note how small they are) in my packages folder. These NuGet packages include the complete "Core CLR" and the cloud-optimized .NET Framework. You can deploy your own CLR and .NET Framework with your app as a NuGet.

Holy crap it's ASP.NET vNext

I can run ASP.NET vNext apps within Visual Studio, of course, and within IIS, but I can also easily "self-host" them from the command line or within my own application. This alpha includes command line tools for running and managing ASP.NET vNext apps.

The "kvm" command allows me to control my environment. I run "kvm list" to see what versions of the ASP.NET vNext are available. I can switch between them on a per-environment basis:

C:\>kvm list

Active Version Runtime Architecture Location
------ ------- ------- ------------ --------
0.1-alpha-build-0418 svr50 x86 C:\Users\scottha\.kre\packages
* 0.1-alpha-build-0418 svrc50 x86 C:\Users\scottha\.kre\packages
0.1-alpha-build-0420 svr50 x86 C:\Users\scottha\.kre\packages
0.1-alpha-build-0420 svrc50 x86 C:\Users\scottha\.kre\packages

I set the active version with "kvm use version" and opened two command prompts, setting different CLR and .NET versions in each.

I’m running the same app twice, once per command prompt. I put version 420 on port 5420 and version 418 on port 5418.

Two Command Prompts two .NET Frameworks

This little app below outputs the current running version of ASP.NET vNext. Here I’m running the same app at the same time under different builds of the next generation of ASP.NET

Two URLs two .NET Frameworks

The project system is also changing - we’re integrating packages.config, NuGet specifications (nuspec), and project files (csprojs) into a unified view of your project dependencies expressed in a project.json file.

NuGet packages and class libraries are treated the same. You get full intellisense in the project.json file and NuGet packages come down automatically and transparently. Even better, let’s say NuGet package Foo.Bar has a bug but you’ve only got the NuGet package. You can make a folder called Foo.Bar in our local project and put the source via "git clone" in that folder. This is great for open source projects. That local version overrides the NuGet, allowing you to easily patch bugs locally in libraries while you wait for a new release. When a new fixed NuGet-distributed version shows up, update the version and delete the local source.

New project system

One of the great aspects of environments like node or rails is that they are "no compile." Just change some code and hit refresh. With the next version of ASP.NET you get the power and throughput of the .NET runtime plus the "Roslyn" compiler-as-a-service for a "no-compile compile." That means means during development time you can just change your C# classes and hit Refresh in the browser. It's the power of .NET with the dynamism of a refresh-and-go development experience.

NOTE: This isn't ASP.NET Websites, or Razor View compilation - this is the whole thing, compiled in memory. You can use Visual Studio for development, or text editors like Sublime, or freakin' Notepad. (Of course, if you want assemblies on disk, you can do that too.)

See my web app’s bin folder in the screenshot below? There’s no assemblies in there because the assemblies never exist on the disk. It’s actually faster and easier to have the compiler do all the work in memory. This way you don’t have to read source, write out dlls, then read the dlls in again. (That DLL is part of the magic that makes it all happen.)

No binaries on disk!

If you like, when your web projects build for deployment, they can also build as NuGet packages. You publish your project and every needed dependency comes along.

You’ll be able to put ASP.NET vNext on your existing servers, any hoster, and Azure of course.

You can opt in or out of the cloud optimized framework for compatibility. The next version of ASP.NET is modular and all about choice. your choice of framework, your choice of runtime, your choice of operating system, your choice of text editor.

ASP.NET vNext is:

  • Cloud and server-optimized
  • ASP.NET MVC and Web API have been unified into a single programming model
  • No-compile developer experience
  • Dependency injection out of the box
  • Side by side - deploy the runtime and framework with your application
  • NuGet everything - even the runtime itself
  • All Open Source via the .NET Foundation and takes contributions

Oh, and by the way

  • ASP.NET vNext (and Rosyln) runs on Mono, on both Mac and Linux today. While Mono isn't a project from Microsoft, we'll collaborate with the Mono team, plus Mono will be added to our test matrix. It's our aspiration that it "just work."
ASP.NET on a Mac

There will be lots of new information and details coming out over the next several months!


Sponsor: Many thanks to Izenda for sponsoring the blog feed this week! Intuitive Ad Hoc Reporting with Stunning Visualizations - Embed real time dashboards into your ASP.NET applications for easy, custom reports across all devices. Download a FREE TRIAL of Izenda Today!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Fixing System.Core 2.0.5 FileLoadException, Portable Libraries and Windows XP support

May 08, 2014 Comment on this post [17] Posted in Bugs | Learning .NET | WPF
Sponsored By

Installing Windows XP to testMy buddy Greg and I are getting ready to launch our little side startup, and I was going through our product backlog. Our app consists of a global cloud service with Signalr, an iPhone app made with Xamarin tools, and a WPF app.

One of the items in our Trello backlog was "Support Windows XP. Gasp!"

I hadn't given this item much thought, but I figure it was worth a few hours look. If it was easy, why not, right?

Our WPF desktop application was written for .NET 4.5, which isn't supported on Windows XP.  I want to my app to support as basic and mainstream a .NET 4 installation as possible.

Could I change my app to target .NET 4 directly? I use the new async and await features extensively.

Well, of course, I remembered Microsoft released the Async Targeting Pack (Microsoft.Bcl.Async) through NuGet to do just this. In fact, if I was targeting .NET 3.5 I could use Omer Mor's AsyncBridge for .NET 3.5, so it's good that I have choices.

I changed my project to target .NET 4, rather than 4.5, installed these NuGets, and recompiled. No problem, right?

However, when I run my application on Windows XP it crashes immediately. Fortunately I have instrumented it with Raygun.io so all my crashes to to the cloud for analysis. It gives me this nice summary:

raygun.io is amazing 

Here's the important part:

FileLoadException: Could not load file or assembly 
'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'
or one of its dependencies. The given assembly name or codebase was invalid.
(Exception from HRESULT: 0x80131047)

That's weird, I'm using .NET 4 which includes System.Core version 4.0. I can confirm what's in the GAC (Global Assembly Cache) with this command at the command line. Remember, your computer isn't a black box.

C:\>gacutil /l | find /i "system.core"
System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL
System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL

OK, so there isn't even a System.Core version 2.0.5 in the GAC. Turns out that System.Core 2.0.5 is the Portable Libraries version, meant to be used everywhere (that means, Silverlight, etc, everywhere) so they made the version number compatible.

Because we're building our iPhone app with Xamarin tools and we anticipate supporting other platforms, we use a Portable Library to share code. But, it seems that support for Portable Libraries were enabled on .NET 4 vanilla by the KB2468871 update.

I don't want to require any specific patch level or hotfixes. While this .NET 4 framework update was pushed to machines via Windows Update, for now I want to support the most basic install if I can. So if the issue is Portable Libraries (which I still want to use) then I'll want to bring those shared files in another way.

You can LINK source code in Visual Studio when you Add File by clicking the little dropdown and then Add as Link:

Adding source code as a Link within Visual Studio

Now my Messages.cs file is a link. See the little shortcut overlay in blue?

A linked file as a little overlay on the icon

I removed the project reference to the Portable Library for this WPF application and brought the code in this way. I'm still sharing core, but just not as a binary for this one application.

Recompile and redeploy and magically .NET 4 WPF application with async/await and MahApps.Metro styling starts up and runs wonderfully on this 12 year old OS with just .NET 4 installed.

For our application this means that my market just got opened up a little and now I can sell my product to the millions of pirated and forever unpatched Windows XP machines in the world. Which is a good thing.


Sponsor: Big thanks to Aspose for sponsoring the blog feed this week. Aspose.Total for .NET has all the APIs you need to create, manipulate and convert Microsoft Office documents and a host of other file formats in your applications. Curious? Start a free trial today.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

FREE Pluralsight video: "Get Involved" in community!

May 07, 2014 Comment on this post [17] Posted in Musings | Open Source
Sponsored By

imageI'm absolutely thrilled to announce that my feature-length collaboration with Rob Conery called "Get Involved" is now available FREE from Pluralsight!

You can watch the whole movie RIGHT now for FREE. No sign up or subscription needed! Please tweet and tell your friends!

http://getinvolved.hanselman.com

We really poured our hearts into this production and we really hope you enjoy it.

In this feature-length production, Scott Hanselman and Rob Conery offer suggestions and advice on how you can get out there, and get involved. Blogging, Twitter, Github, StackOverflow, User Groups and Conferences: all of this can make you a happier, more productive developer and inspire you to take your career to the next level.

You certainly don't have to be social to be better at writing code - but sharpening your skills this way helps you when it comes time for a job interview, a yearly review where a promotion is on the line, or when you want to start running an Open Source project.

If you're a fan of This Developer's Life you know how tightly Rob and I like to produce things - this video is no exception.

Filmed on the streets of Portland and at a Portland user group, we talk about Blogging, Twitter, Github, StackOverflow, Open Source, Speaking, User Groups and Conferences - all of this hoping to make you a happier, more productive, more connected developer. We want to inspire you and perhaps to take your career to the next level.

Additionally, we stretched far beyond Portland to seek out the other people who active in the social technology space!

  • Jon Skeet joins us to talk about what a Good Question is on StackOverflow - and also how you can gain reputation by providing Good Answers - and edits to Good Questions!
  • We venture out to the Portland Area DotNet Users Group (PADNUG) and meet a few developers who have just started going - as well as people who have been there for years.
  • While we were there, I gave a 10-minute lightning talk on Azure - a great way to get started speaking if you're not a fan of public speaking. Rob filmed the whole thing.

By the way, if you do have a Pluralsight Subscription, you've got access to thousands of hours of technical video training, like my other video on technical presenting!

image

The Art of Speaking - Become a better technical public speaker

Have you thought about speaking on technology publically? Maybe you want start talking a local user groups and then work your way up to larger regional code camps? "The Art of Speaking" is an 80 min Pluralsight course that Rob and I created to help you do just that!

You'll learn all about:

  • The Speaker Mindset
    • Not Wasting Time
    • What to do, What Not to Do
    • Defining a Perfect Talk
  • Preparation
    • Choosing Your Demo
    • Choosing Your Delivery Style
    • Handling Pressure
    • Engaging the Audience
    • Code vs. Slides
    • Creating an Outline
    • Creating the Story
    • Building a DemoYou have not watched this Clip.
    • Building a More Complex DemoYou have not watched this Clip.
    • Creating Your Slides
  • ExecutionYou have not watched this Module.
    • The Unexpected
    • The Tech Check
    • The Delivery

Keep an eye out for my next video with Rob, coming very soon exclusively to Pluralsight Subscribers!

Rob has a lot of great videos as well like these and many more!

Rob and I also have a one hour video where we move the This Developer's Life podcast website to Microsoft Azure LIVE, so check that out.

Many, many, thanks to Pluralsight for giving this video to the community for free! If you're on Twitter, go thank them now @pluralsight.


Sponsor: Big thanks to Aspose for sponsoring the blog feed this week. Aspose.Total for .NET has all the APIs you need to create, manipulate and convert Microsoft Office documents and a host of other file formats in your applications. Curious? Start a free trial today.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.