So, I’m gonna say require, and then image optimizer just like this. So, now that we have that and we know what the image file currently is now we can try to compress it. He looks like he’s pretty happy, which I don’t understand because he has to write PHP code, so I know back when I had to do that I wasn’t happy, but he can be happy if he wants to be. So, this is the image that we’re gonna be compressing. Definitely not something that you’d want to put on a website, or else it would take a very long time to load. It’s Coder Guy, and if you want to see the size of Coder Guy you can see that currently Coder Guy is 4.7 megabytes, so it’s a pretty large file. And the file that I want to compress is this file right here. So, I’m gonna start up a interactive Ruby session here. So, it looks like it went out, and installed all of those for me.Īnd now with all of those installed let me clear out my output here, and I’m going to say IRB. I personally find that this is a tool that comes in very handy when I’m just using it on my own system, so the reason why I even have the idea for creating this guide was because I wanted to compress some of the images files I was putting into a react application, and then was a really nice easy way of doing that. And if you’re wanting to put this in a Rails Project you just follow the exact same approach as you would for adding any gem. So, assuming you have a modern version of Ruby then you can say gem install image optimizer just like this. So, now that you have that now it’s gonna be time to install the image optimizer gem. You just copy that, and then you’d be able to run the exact same command that I just ran assuming that you do not have it installed on your system. You can go there, and it’ll give you the exact command to copy and paste directly into the terminal. You can go to Homebrew SH, and the full URL is just brew.sh. Now, if you do not have Homebrew installed on your system then you can simply go … Let me show how to get there. It shows that all of these are already installed and up to date, so if you do not have those installed on your system they might take a little bit longer. I already have these installed on my system, so it’ll take a little bit shorter period of time assuming they haven’t pushed any updates since the last time that I installed these on my system. Now you can simply run Homebrew and install these. And those dependencies are gonna optipng, which is just short for optimization, or optimize png, jpegoptum, then gifsicle, and then pngquant. And then you need to install a few dependencies before we can actually get into installing the gem. Now, if you’re on a Mac then you can use the Homebrew tool in order to install this, and you’d run the command brew install. We’re going to be diving into how to use the image optimizer gem. In this Ruby Programming Tutorial, we are gonna walk through how we can optimize the size of our image files using a RubyGem. There are a number of online utilities that can compress images, but this guide shows how to compress them on your own system using the ImageOptimizer RubyGem. Image compression can make a significant difference in the performance of your applications.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |