What I learned this week
One of the great things I like about the software development profession is that you can never learn everything and there's always something new to learn. I started thinking that I needed to keep track of the new things I learned. I decided I'm going to start posting every time I have three or four new things that I have learned.
I normally have a goal trying to learn at least one new thing per day, some days it's hard some days it's easy to get more than a few. I have multiple sources that I use to learn new fun and exciting things from social media, blogs, virtual conferences, YouTube and news do company events.
For this week I have learned how to make the background of an image transparent, how to get a color palette from an image, and that there is a difference in Blazor JSON serialization.
Transparent Image
To be able to make an image with a transparent background you need a software package that will remove the background color. There is a lot of image software packages available, all the Adobe's and Adobe clones, plus there's plenty of online free applications.
The one I found and used is called PhotoPea at https://Photopea.com. This is a free online Photoshop type application.
Here are the steps to follow to take an image in making a transparent background:
1. Open your browser to http://photopea.com
2. Go to “File Open” on the menu and select the image you want to work on
3. Once the image has loaded, from the toolbar select the “Object Selector”
4. Right-click on the “Object Selector” and select the “Magic Wand”
5. Go to the top of the tab and change the select grade to at least 125
6. Click on the background
7. Hit the delete key
8. From the menu “File” select save as and make sure you select PNG
And that's it you now have an image with a transparent background. I never realized how easy it is to do this I should have been able to do it a long time ago.
Generate a Color Palette from an image
One of the hardest things I find to do when I'm creating a new web application or website is to get colors that match what I'm trying to do. I've used several different types of color palette selectors/generators where you pick a couple of primary colors and tell you to pick the secondary and tertiary colors. I never really felt that comfortable with them. I finally have found something I really like. It is a color generator where you upload an image and it will tell you the colors that match with it. This is a free web application that is located at https://www.canva.com/colors/color-palette-generator/.
It is very simple:
1. Go to the website https://www.canva.com/colors/color-palette-generator/
2. Select upload image
3. Browse and select the image of your website or web application
4. Click select
5. There you have it, the application comes up with different color options for you to choose from that all correlate with your image
When I first found this application I went through and put in several different images that I had that I've been wanting to make websites or web applications with and selected all the colors it was very cool to me.
Different Blazor JSON Serialization
I ran into this when I was trying to update two projects that I have. I created the same application, a daily inspirational web app that shows you a nice picture and gives you a nice quote for the day.
The application is simple it pulls the quotes from a JSON file that's stored on the file system. I found more quotes that I wanted to add it to the applications. I had created a Blazor Server-Side project and a Blazor Client-Side project. Both of these applications have been in production for several months now. They are hosted on Azure, the Server-Side app as an app service, and the Client-Side as a blob storage static website.
I first updated the Server-Side with the new quotes in the JSON file, saved it, and ran the application locally. Everything worked great.
I then copied the exact same JSON file to the Client-Side application, saved it, and ran it. This application crashed an initialization of the quotes.
This confused me at first, the same file was being used in both applications. Why would it worked in one application and didn't work in another application?
After some more investigation, I came to the conclusion that there were two different civilizations being used between the two applications.
Server-Side Application Json Serialization:
quotes = System.Text.Json.JsonSerializer.Deserialize<List<Quote>>(data);
Client-Side Application Json Serialization:
quotes = await Http.GetFromJsonAsync<List<Quote>>("sample-data/quote2.json");
I was in disbelief about this for a little while. I cannot believe that there be a difference between the JSON serialization and the libraries. After a little bit more investigation, I realized on the server-side we are reading in the file directly from the file system. On the client-side, we were calling API that was pulling it down and then sterilizing it.
After some additional troubleshooting I came to the conclusion there has to be something about the file. I was not sure what but I figured there had to be something.
I opened the text file in Visual Studio editor and sure enough, I found some special characters. There were only three or four of 'em but sure enough, was enough to cause a problem. It was the ‘ character. Once I did a search-replace from the special character to the normal one everything started working fine.
This is post because if I run into this again, I want to be able to find what I did before to fix it.
Those are the three things that I have learned this week. The transparent images I should have already known, the colors from an image are really cool and the different Jason serialization hopefully will keep me from wasting time troubleshooting that same issue in the future.
Comments
Post a Comment