{"id":209,"date":"2024-02-02T00:10:00","date_gmt":"2024-02-02T00:10:00","guid":{"rendered":"https:\/\/davagordon.co.uk\/blog\/?p=209"},"modified":"2024-05-12T02:31:18","modified_gmt":"2024-05-12T01:31:18","slug":"unlocking-lightning-fast-websites-harness-the-power-of-image-optimisation-with-this-free-tool","status":"publish","type":"post","link":"https:\/\/davagordon.co.uk\/blog\/unlocking-lightning-fast-websites-harness-the-power-of-image-optimisation-with-this-free-tool\/","title":{"rendered":"Revolutionise Your Website Speed: Boost Speed with the Ultimate Free Image Optimisation Tool!"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Website performance is one of the most critical things that affect both user experience and search engine result placement in today\u2019s digital marketplace. Images can have a big influence on how a website loads. In this post, we will talk about why you should optimise images and introduce ImageMagick which is an excellent free tool. We will also provide a more comprehensive and easier to understand script for optimising photographs on many different types of servers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Significance of Image Optimisation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Your website\u2019s load speed may be reduced significantly by large and non optimised images, which can cause it to bounce more and rank poorer in search engines. Image optimisation is the process of reducing image sizes by compressing the image without affecting quality, leading to faster loading times, improved user experience and also better SEO.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Enter ImageMagick.<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">ImageMagick, an open source software package, is a powerful tool for image generation, editing, and optimisation. ImageMagick is a fantastic solution for image optimisation on many server types since it has a command-line interface (CLI) and is compatible with a wide range of operating systems.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Improved script for user friendly image optimisation.<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To make the image optimisation process more efficient and user friendly, we improved a bash script that uses ImageMagick. The software enables users to resize photographs, convert them to WebP format, and speed up the optimisation process. Here&#8217;s an overview of the script&#8217;s enhancements:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. Color Coded Output<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To improve visibility and user engagement, the script now has color coded outputs. Green signifies successful operations, however red warns of future problems.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. Overwrite Confirmation<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before overwriting existing WebP files, the script now displays a warning and requests approval from the user. This avoids unintentional data loss and ensures a safer optimisation procedure.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3. Informative Messages<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Throughout the script, we&#8217;ve included relevant messages to keep users up to date on the current activities. This allows for a more clear and user friendly experience.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using the Image Optimisation Script<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To use the latest version of the script, follow these instructions:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n## Using the Image Optimisation Script\n\nTo use the latest version of the script, follow these instructions:\n\n1. Create a new file named `optimise_image.sh` using the following command:\n\n   ```bash\n   touch optimise_image.sh\n<\/pre><\/div>\n\n\n<ol class=\"wp-block-list\">\n<li>Open the newly created script file in your preferred text editor. You can use nano, for example:<\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nnano optimise_image.sh\n<\/pre><\/div>\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li><span style=\"color: rgb(55, 65, 81); font-family: S\u00f6hne, ui-sans-serif, system-ui, -apple-system, &quot;Segoe UI&quot;, Roboto, Ubuntu, Cantarell, &quot;Noto Sans&quot;, sans-serif, &quot;Helvetica Neue&quot;, Arial, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;, &quot;Noto Color Emoji&quot;; font-size: 16px;\">Copy the enhanced bash script provided below and paste it into the <\/span><code style=\"border: 0px solid rgb(217, 217, 227); box-sizing: border-box; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(69,89,164,.5); --tw-ring-offset-shadow: 0 0 transparent; --tw-ring-shadow: 0 0 transparent; --tw-shadow: 0 0 transparent; --tw-shadow-colored: 0 0 transparent; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; font-size: 0.875em; color: var(--tw-prose-code); font-weight: 600; font-family: &quot;S\u00f6hne Mono&quot;, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace !important;\">optimise_image.sh<\/code><span style=\"color: rgb(55, 65, 81); font-family: S\u00f6hne, ui-sans-serif, system-ui, -apple-system, &quot;Segoe UI&quot;, Roboto, Ubuntu, Cantarell, &quot;Noto Sans&quot;, sans-serif, &quot;Helvetica Neue&quot;, Arial, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;, &quot;Noto Color Emoji&quot;; font-size: 16px;\"> file:<\/span><\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n#!\/bin\/bash\n\n# Colors for better output\nGREEN=&#039;\\033&#x5B;0;32m&#039;\nRED=&#039;\\033&#x5B;0;31m&#039;\nNC=&#039;\\033&#x5B;0m&#039; # No Color\n\n# Function to display usage instructions\nusage() {\n    echo &quot;Usage: $0 &#x5B;-s size] &#x5B;-d directory | -i image]&quot;\n    echo &quot;  -s size       : Resize image to specified size (e.g., 1200x900)&quot;\n    echo &quot;  -d directory  : Directory containing images to be converted&quot;\n    echo &quot;  -i image      : Single image file to be converted&quot;\n    exit 1\n}\n\n# Default values\nQUALITY=70\nSIZE=&quot;&quot;\nIMAGE=&quot;&quot;\nDIRECTORY=&quot;&quot;\nOUTPUT_DIR=&quot;\/path\/to\/output\/images&quot;\n\n# Parse command line options\nwhile getopts &#039;s:d:i:&#039; flag; do\n    case &quot;${flag}&quot; in\n        s) SIZE=&quot;${OPTARG}&quot; ;;\n        d) DIRECTORY=&quot;${OPTARG}&quot; ;;\n        i) IMAGE=&quot;${OPTARG}&quot; ;;\n        *) usage ;;\n    esac\ndone\n\n# Check if no options were provided\nif &#x5B; -z &quot;$SIZE&quot; ] &amp;&amp; &#x5B; -z &quot;$DIRECTORY&quot; ] &amp;&amp; &#x5B; -z &quot;$IMAGE&quot; ]; then\n    usage\nfi\n\n# Function to convert image\nconvert_image() {\n    local image=$1\n    local size=$2\n\n    # Extract filename without extension\n    filename=$(basename -- &quot;$image&quot;)\n    filename=&quot;${filename%.*}&quot;\n\n    # Check if WebP file already exists\n    if &#x5B; -f &quot;$OUTPUT_DIR\/$filename.webp&quot; ]; then\n        read -p &quot;${RED}Warning: ${filename}.webp already exists. Overwrite? (y\/n): ${NC}&quot; overwrite\n        if &#x5B; &quot;$overwrite&quot; != &quot;y&quot; ]; then\n            echo &quot;Skipped $image.&quot;\n            return\n        fi\n    fi\n\n    # Convert to WebP, resize, strip metadata, and save\n    echo &quot;Converting ${filename} to WebP format...&quot;\n    magick convert &quot;$image&quot; -resize &quot;$size&quot; -quality $QUALITY -strip &quot;$OUTPUT_DIR\/$filename.webp&quot;\n    echo &quot;${GREEN}Conversion of ${filename} complete.${NC}&quot;\n}\n\n# Create output directory if it doesn&#039;t exist\nmkdir -p &quot;$OUTPUT_DIR&quot;\n\n# Process images\nif &#x5B; ! -z &quot;$DIRECTORY&quot; ]; then\n    for image in &quot;$DIRECTORY&quot;\/*.{jpg,png,jpeg}; do\n        if &#x5B; -f &quot;$image&quot; ]; then\n            convert_image &quot;$image&quot; &quot;$SIZE&quot;\n        fi\n    done\nelif &#x5B; ! -z &quot;$IMAGE&quot; ]; then\n    if &#x5B; -f &quot;$IMAGE&quot; ]; then\n        convert_image &quot;$IMAGE&quot; &quot;$SIZE&quot;\n    else\n        echo &quot;${RED}Error: File $IMAGE does not exist.${NC}&quot;\n        exit 1\n    fi\nfi\n\necho &quot;${GREEN}Conversion complete.${NC}&quot;\n\n<\/pre><\/div>\n\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li>Save the changes and exit the text editor.<\/li>\n\n\n\n<li>Make the script executable with the following command:<\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nchmod +x optimise_image.sh\n<\/pre><\/div>\n\n\n<ol class=\"wp-block-list\" start=\"5\">\n<li>You are now ready to use the script for optimising your images. Run the script with appropriate options to optimise images according to your preferences.<\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n.\/optimise_images.sh -s size -d directory\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li>`<code>-s size<\/code>`: Resize image to the specified dimensions (e.g., 1200&#215;900).<\/li>\n\n\n\n<li>`<code>-d directory<\/code>`: Directory containing images to be converted.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Additionally, you may optimise a single image with the following command:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n.\/optimise_images.sh -s size -i image\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">`<code>-i image<\/code>`: Single image file to be converted.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Optimising images is a crucial step in ensuring optimal website performance. ImageMagick, coupled with our user-friendly script, empowers website administrators to efficiently enhance loading speed and user experience across different server types. By investing time in image optimisation today, you pave the way for a faster, more responsive, and user-friendly website tomorrow.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Explore more <a href=\"https:\/\/davagordon.co.uk\/blog\/category\/devops-and-testing\/\" title=\"DevOps &amp; Testing\">DevOps<\/a> insights and tools in our dedicated category for comprehensive web optimisation strategies.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Website performance is one of the most critical things that affect both user experience and search engine result placement in today\u2019s digital marketplace. Images can have a big influence on how a website loads. In this post, we will talk about why you should optimise images and introduce ImageMagick which is an excellent free tool. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":215,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[35,10,37,36],"class_list":["post-209","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-digital-marketing-strategies","tag-devops","tag-how-to","tag-optimisation","tag-website-performance"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/davagordon.co.uk\/blog\/wp-json\/wp\/v2\/posts\/209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/davagordon.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/davagordon.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/davagordon.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/davagordon.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=209"}],"version-history":[{"count":13,"href":"https:\/\/davagordon.co.uk\/blog\/wp-json\/wp\/v2\/posts\/209\/revisions"}],"predecessor-version":[{"id":253,"href":"https:\/\/davagordon.co.uk\/blog\/wp-json\/wp\/v2\/posts\/209\/revisions\/253"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/davagordon.co.uk\/blog\/wp-json\/wp\/v2\/media\/215"}],"wp:attachment":[{"href":"https:\/\/davagordon.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/davagordon.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/davagordon.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}