Fallback for SVG images by automatically creating PNG versions on-the-fly

Overview

ScreenShot

SVGMagic - Cross browser SVG

This repository is no longer actively mainted. It has proven to be very usefull back in 2013, but these days SVGs are supported by pretty much all major browsers. The plugin will continue to work, but no guarantees will be given over the API's availability. It has been a great ride!

This ease-to-use jQuery plugin will create a fallback for .SVG images on your website. When the plugin notices that the visitors browser doesn't support .SVG images it will replace those images with new .PNG images. Those .PNG images are created on the run using a serverside script. When the visitors browser does support .SVG images it will just go back to sleep.

A big advantage of SVGMagic is that you don't have to create multiple versions of your images. You can just focus on the .SVG images and let SVGMagic do the rest.

You can find more information and demos on our website.

Build Status

SVG... what/why?

SVG is a vector graphics format, meaning it's perfectly scalable. Whatever size it needs to display at, or whatever screen it needs to display on, an SVG will adapt perfectly. This means that you can use the same image for desktop and mobile (including Retina) visitors. They all get a perfectly sharp image.

Installation

Just include the script in your header and call the plugin in your $(document).ready()

<script src="SVGMagic.min.js"></script>
<script>
	$(document).ready(function(){
		$('img').svgmagic();
	});
</script>

SVGMagic also supports backgroundimages. You need to parse the div containing the backgroundimage including the backgroundimage option.

<script src="SVGMagic.min.js"></script>
<script>
	$(document).ready(function(){
		$('.bgimage').svgmagic({
            handleBackgroundImages: true
        });
	});
</script>

Options

You can parse an options object into SVGMagic. Currently it supports the following options:

$('img').svgmagic({
    temporaryHoldingImage:  null, // Image that will appear when an image gets converted
    forceReplacements:      false, // Force replacement in all browsers
    handleBackgroundImages: false, // Search the dom for CSS background images
    additionalRequestData:  {}, // Add extra data to the ajax request.
    postReplacementCallback:null, // Function to run before replacement

    // New options
    remoteServerUri:        'https://bitlabs.nl/svgmagic/converter/3/', // Uri of the (remote) API script
    remoteRequestType:      'POST', // Request type for the API call
    remoteDataType:         'jsonp', // Data type for the API call
    debug:                  'false' // Show usefull debug information in the console
});

additionalRequestData

The additionalRequestData option gives you the posibility to add extra data to the ajax request. The default API script supports two extra options: {secure: true} and {dumpcache: true}.

Local development

SVGMagic needs public access to the images on your website, which means that you can't use it when developing in a local environment. In case you still need to use the plugin you can download the converter.php script and place it on your local machine.

Support

The plugin is tested in Internet Explorer Version 7 and 8 (other browsers already support SVG files).

Security / How it works

The script makes use of a server side php script that converts the SVG to an PNG. The plugin will send a request to the server containing the images' sources. The server will then grab those images, convert them to PNG, temporarily save them and send the URL of the new images back to the plugin. When the plugin receives the new URL it will replace the .SVG images with the new ones.

This will only happen when the plugin notices that the user's browser doesn't support SVG images. At the moment IE8 and lower and Android 2.* don't support SVG images.

Demo

A demo of SVGMagic can be found on the SVGMagic website.

Known bugs

  • When many images need to be replaced the URL can get too long which will result in a server 414 error.

Changelog

3.0.0 (2014-11-22)

Client:

New features:
    - SVGMagic can now return usefull debug information while replacing SVG images.
    - Added timeout to ajax request. Show debug information when timeout gets exceeded.

New options:
    - debug: Show usefull debug information in the console

Documentation:
    - Added changelog to the bottom of the README
    - Automatically return images over https when request was over https.

Server:

New features:
    - Fully rewrite of the server script. The server will now provide much more information about the convert process.
    - Response will contain the creation date of cached images.
    - Data images are now also cached.

2.4.0 (2014-08-01)

New features:
    - Add extra post data to the ajax request
    - Now also finds data:image SVGs

New options:
    - temporaryHoldingImage:    replacement for preloader
    - forceReplacements:        replacement for testmode
    - handleBackgroundImages:   replacement for backgroundimage
    - additionalRequestData:    send extra data to the server that replaces the SVGs for PNGs
    - postReplacementCallback:  callback function that will be executed before replacement
    - remoteServerUri:          the URI of the remote server that converts the images to PNG
    - remoteRequestType:        set the type of the ajax request (post/get)
    - remoteDataType:           the datatype sent to and received from the remote server

Deprecated options:
    - preloader         > temporaryHoldingImage
    - testmode          > forceReplacements
    - backgroundimage   > handleBackgroundImages
    - secure            > additionalRequestData
    - callback          > postReplacementCallback
    - dumpcache         > additionalRequestData
Comments
  • include svg magic into wordpress plugin

    include svg magic into wordpress plugin

    hi dirk, how can i implement svgmagic into a wordpress plugin?

    i tried:

    ##################################################################
     enable svgmagic fallback (auto png creation)
    ##################################################################
    
    function fallback_svg(){
    wp_register_script( 'jquery.svgmagic', WP_PLUGIN_URL.'/svg-images/svgmagic.js', array( 'jquery' ), "2.3.1", 1 );
    wp_enqueue_script( 'jquery.svgmagic' ); 
    }
    add_action( 'wp_enqueue_scripts', 'fallback_svg' );
    

    but it won't work - maybe it's because it was with an older version. i am not so good in writing plugins, so any help is highly appreciated. also i have not a very good testing area (older browsers etc.) it would be cool to implement svgmagic with the converter.php

    best regards telemarker

    opened by telemarker 11
  • Demo not working?

    Demo not working?

    Hi there, First of all, great plugin! Exactly what I was looking for!

    If I stand correctly, if you set the forceReplacements: true option, it will replace the svg image for an png no matter what browser you're viewing the content in right? Well if I view the demo in Firefox for example, I only see two svg images? Am I missing something? https://dirkgroenen.github.io/SVGMagic/demo.html

    Another question, will it matter if my img is inside a picture element like this:

    <picture>
        <!--[if IE 9]><video style="display: none;"><![endif]-->
        <source srcset="image.svg">
        <!--[if IE 9]></video><![endif]-->
        <img srcset="image.svg" alt="alt text" />
    </picture>
    

    p.s. In Chrome it does swap the left svg image

    opened by Twansparant 9
  • Does it work with SVG sprites by using xlink:href=

    Does it work with SVG sprites by using xlink:href="#spritename"?

    SVG's sprites are multiple SVG's combined into one file by using a block or definitions. Does SVGMagic support linking to those symbols using xlink:href="#spritename"?

    Idea 
    opened by iainvdw 9
  • IE8 compatibility

    IE8 compatibility

    Hi, thx for the great plugin, unfortunately the new version (2.3.1) seems not to work in IE8 anymore. Version 2.1.4 worked fine. Exept after a long page-load-time, the script breaked. Any idea?

    bug 
    opened by benunternaehrer 7
  • Inline SVGs?

    Inline SVGs?

    First of all, great work, really useful plugin!

    Would be nice though if it would also work with inline svg graphics =)! Any thoughts about implementing this?

    Idea 
    opened by exside 3
  • svgmagic.bitlabs.nl replace lang param in html tag

    svgmagic.bitlabs.nl replace lang param in html tag

    Hello guys,

    your plugin is awesome. This ticket is for your website. The content is en english, but in your <html> you have this param lang="nl-NL". I know is a really small thing, but it's importat. For example the facebook like plugin is in Dutch. I think the lang also affect in some point the SEO?

    Another suggestion: use the gh-pages branch to deploy the website is possible, or you are using technologies that GitHub doesn't support?

    opened by matysanchez 3
  • Stopped working in IE8

    Stopped working in IE8

    Hi there,

    The current version 3.0.0 just stopped working for me... Are you by any chance having problems on your server? The demo doesn't work either anymore in IE8. I only have the following line in my script:

    $('img').svgmagic({forceReplacements: true }); // true for debugging
    

    Thanks, Toine

    opened by Twansparant 2
  • Background image on links

    Background image on links

    Just wanted to say this is an amazing plugin.. really great work!!

    I have noticed if you are trying to replace SVG background image on links the replacement images don't show, I have tested in IE8 on W7 and XP. I only had a few links with bg images anyway so just replaced them via CSS.. great plugin again!!

    opened by atelierandy 2
  • Changing the license to Apache

    Changing the license to Apache

    After some digging in into the licenses I want to change the current SVGMagic license from GPL to Apache. As a formality I have to ask this to the contributers ( @craigfowler ). Do you agree with changing the license to Apache?

    question 
    opened by dirkgroenen 2
  • getReplacementUris vs getReplacementUrisFromRemoteService

    getReplacementUris vs getReplacementUrisFromRemoteService

    @craigfowler I've finally merged your fork of SVGmagic to this main repo, but after merging I stumbled on some problems/questions.

    The script checks if images need to be replaced, and if so it calls the getReplacementUris function. However, this function doesn't replace the images. I've edited the function call to the getReplacementUrisFromRemoteService function which, after some little modifications, does replace the images.

    May I ask why you've added this function to the script and what it should do?

    bug question 
    opened by dirkgroenen 2
  • jQuery plugin should support chaining by returning 'this'.

    jQuery plugin should support chaining by returning 'this'.

    Generally jQuery plugins which do not return another value should return 'this'. This makes things like the following possible:

    $('img.svg')
      .svgmagic()
      .addClass('svg_replaced');
    

    See http://learn.jquery.com/plugins/basic-plugin-creation/#chaining

    opened by craigfowler 2
Releases(3.0.1)
Owner
Dirk Groenen
Consulting Lead Developer - with a strong focus on Javascript/Angular
Dirk Groenen
Landscape Generator is An open Source web application that generates landscape drawings randomly, then gives you the ability to edit it and export it as SVG or PNG.

Landscape Generator ## About Landscape Generator is An open Source web application that generates landscape drawings randomly, then gives you the abil

null 9 Apr 15, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Lightweight library to copy PNG and JPG images to clipboard

Copy Image Clipboard Created with ❤️ by Luan Eduardo da Costa | Follow me on Linkedin ?? About This library allows you to copy JPG and PNG images (onl

Luan Eduardo da Costa 34 Nov 29, 2022
Making VSCode extensions ON-THE-FLY, without the ceremony of creating a new node project!

easy-extensibility Extend VSCode without the ceremony of making a full extension! Just write your code anywhere and it'll be part of VSCode! Features

Musa Al-hassy 13 Nov 28, 2022
Asciifly is a webapp where you can asciify images and youtube videos on the fly.

Asciifly Asciifly is a webapp where you can asciify images and youtube videos on the fly. Come visit at https://asciifly.com Hosting I'm hosting this

André Esser 7 May 23, 2022
Fallback JS - JavaScript library for dynamically loading CSS and JS files

Fallback JS - JavaScript library for dynamically loading CSS and JS files. Also provides the ability to load multiple files from a CDN with multiple fallback options and shimming!

Dolox Inc. 311 Nov 13, 2022
Extension forcing Reddit videos to be played by the fallback player.

⚡ FRP: The "Fuck Reddit Player" extension Simple extension to force Reddit videos to be played by the fallback player. Installation: ?? addons.mozilla

Akiyue 9 Oct 21, 2022
Extension forcing Reddit videos to be played by the fallback player.

⚡ FRP: The "Fuck Reddit Player" extension Simple extension to force Reddit videos to be played by the fallback player. Installation: ?? addons.mozilla

あずみ 9 Oct 21, 2022
🍎Transform an SVG icon into multiple themes, and generate React icons,Vue icons,svg icons

IconPark English | 简体中文 Introduction IconPark gives access to more than 2000 high-quality icons, and introduces an interface for customizing your icon

Bytedance Inc. 6.8k Jan 5, 2023
caniuse.com but for PHP - a searchable list of new and deprecated features in recent PHP versions

caniphp.com caniphp.com is like caniuse.com but for PHP features. It's a simple search of PHP features that added, deprecated and removed in recent ve

Ross Wintle 95 Dec 25, 2022
🪵 Aggressively find a packages changelog (or releases) between versions.

?? changelogd Aggressively find a packages changelog (or releases) between versions. Status: Early Access Please report any issues ?? Made possible by

Harlan Wilton 8 May 10, 2022
Minimal versions of popular analytics libraries. Reduce the impact of third-party scripts on your application.

minimal-analytics This project aims to provide minimal implementations of popular analytics libraries. It's aimed at users who want to reduce the impa

James Hill 32 Dec 25, 2022
A full documentation on everything we know about Alpha 1.0.16 versions.

Minecraft's Alpha 1.0.16 Versions Before you start, make sure to watch RetroGamingNow's video about this first. Highly influenced (technically a port

_NexTre_ 44 Dec 23, 2022
logs ROBLOX's updates and new versions

roblox-update-notifier logs ROBLOX's updates and new versions This is meant to be ran in NodeJS, 24/7, using something like pm2. NPM packages required

null 5 Oct 23, 2022
generate a map server side and save/return it as png image

NFT map generator Request a new map to be generated with latitude and longitude params, for example http://localhost:3000/maps?lat=45.3579&lng=9.4427

Mattia Asti 3 Jul 12, 2022
Converts your IPv4 address to a 4x4 2-bit PNG which you can extract the IP from.

IP-to-PNG Converts your IPv4 address to a 4x4 2-bit PNG which you can extract the IP from. https://www.npmjs.com/package/ip2png Run npm install ip2png

Görkem / Federal 18 Nov 30, 2022