I am using javascript to make a downloadable button for JPG & PNG images. it ill directly download any image/pdf/gif/png/etc.
<style>
.harishcouponbtn {
   font-size: 1em;
    padding: 1em 2em;
    color:#fff;
    background: #24871b;
    border: 1px solid;
    border-color: #155010 #13470e #103b0c #13470e;
    border-radius: 0.25em;
    text-align: center;
    display: inline-block;
    cursor: pointer;
    text-decoration: none;
    line-height: 1em;
    background: -webkit-gradient(linear, left bottom, left top, color-stop(0, #195d12), color-stop(1, #24871b));
}
</style>
      <button class=”harishcouponbtn” onclick=”return download(‘/wp-content/uploads/2022/09/20112347/Winter-Tire-Rebates-Coupon-5.jpg’)”>
         <span>Download Coupon</span>
      </button> </div></div>
<script>
function download(url)
{
var source = url ;
   const fileName = source.split(‘/’).pop();
    var el = document.createElement(“a”);
    el.setAttribute(“href”, source);
    el.setAttribute(“download”, fileName);
    document.body.appendChild(el);
     el.click();
    el.remove();
   return false;
}
</script>

Leave a Reply

Your email address will not be published. Required fields are marked *