issue133:inkscape
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue133:inkscape [2018/06/08 09:02] – d52fr | issue133:inkscape [2018/06/17 10:53] (Version actuelle) – christo.2so | ||
---|---|---|---|
Ligne 5: | Ligne 5: | ||
Broadly speaking, there are four ways to include an Inkscape-created image in a web page. Each has its own pros and cons, which are outlined in the table shown above.** | Broadly speaking, there are four ways to include an Inkscape-created image in a web page. Each has its own pros and cons, which are outlined in the table shown above.** | ||
- | Durant les six dernières années, cette série a détaillé presque chaque élément d' | + | Durant les six dernières années, cette série a détaillé presque chaque élément d' |
- | En surface, | + | En surface, |
- | En gros, il y a quatre façons d' | + | En gros, il y a quatre façons d' |
**The first method is to simply avoid the whole SVG question entirely and export your image to a PNG file – possibly even converting it to a JPEG afterwards to reduce the file size, if the image doesn’t require transparency. The resultant raster image can be included in a web page via an <img> tag, used on social media sites or blogs, and generally be treated the same way as a photo from a phone or digital camera. Because you’re effectively creating a snapshot of the image as it appears in Inkscape, you also don’t have to worry about missing fonts, flowed text, or mismatches in browsers’ rendering engines. The downside is that the exported raster image is no longer infinitely scalable in the same way as a vector image. You also lose any concept of the individual objects that made up the image, so it’s not possible to manipulate them individually using CSS animations or JavaScript. | **The first method is to simply avoid the whole SVG question entirely and export your image to a PNG file – possibly even converting it to a JPEG afterwards to reduce the file size, if the image doesn’t require transparency. The resultant raster image can be included in a web page via an <img> tag, used on social media sites or blogs, and generally be treated the same way as a photo from a phone or digital camera. Because you’re effectively creating a snapshot of the image as it appears in Inkscape, you also don’t have to worry about missing fonts, flowed text, or mismatches in browsers’ rendering engines. The downside is that the exported raster image is no longer infinitely scalable in the same way as a vector image. You also lose any concept of the individual objects that made up the image, so it’s not possible to manipulate them individually using CSS animations or JavaScript. | ||
Ligne 15: | Ligne 15: | ||
The second approach relies on the fact that most modern browsers do a pretty decent job of rendering SVG – so why not just use the SVG file directly, rather than converting to a raster format first? This is as simple as referencing an SVG file in your <img> tag, rather than a PNG or JPEG. Because the internal structure of your SVG is preserved, the browser knows about individual objects, so can animate them using CSS. In theory it could also allow JavaScript, but that’s prevented when using images like this, for security reasons.** | The second approach relies on the fact that most modern browsers do a pretty decent job of rendering SVG – so why not just use the SVG file directly, rather than converting to a raster format first? This is as simple as referencing an SVG file in your <img> tag, rather than a PNG or JPEG. Because the internal structure of your SVG is preserved, the browser knows about individual objects, so can animate them using CSS. In theory it could also allow JavaScript, but that’s prevented when using images like this, for security reasons.** | ||
- | La première méthode évite complètement la question | + | La première méthode évite complètement la question du SVG en exportant votre image vers un fichier PNG - avec même la possibilité |
- | La seconde approche s' | + | La seconde approche s' |
**What does security have to do with an SVG image, you may wonder. Consider that many social media platforms, forums, and other websites, will let you upload your own SVG file, then expose it to other people on the site by using an <img> tag. This would effectively give a malicious user a means to run their own JavaScript under the guise of the hosting website. The code could capture user’s keypresses, spoof a login dialog to record passwords, or redirect the user to another site entirely. Given that being able to upload an SVG file to a site and have it rendered as an image is generally a good thing, but that unfettered permission to run JavaScript in such a file could easily be abused, browsers take the sensible approach of allowing CSS animations to run (giving SVG an edge over raster images), but disallowing any JavaScript. | **What does security have to do with an SVG image, you may wonder. Consider that many social media platforms, forums, and other websites, will let you upload your own SVG file, then expose it to other people on the site by using an <img> tag. This would effectively give a malicious user a means to run their own JavaScript under the guise of the hosting website. The code could capture user’s keypresses, spoof a login dialog to record passwords, or redirect the user to another site entirely. Given that being able to upload an SVG file to a site and have it rendered as an image is generally a good thing, but that unfettered permission to run JavaScript in such a file could easily be abused, browsers take the sensible approach of allowing CSS animations to run (giving SVG an edge over raster images), but disallowing any JavaScript. | ||
Ligne 23: | Ligne 23: | ||
Unfortunately this method does come with one big drawback – though it’s a problem that diminishes every year. Because you are relying on your browser’s rendering engine to draw each object in your image, you no longer have complete control over the appearance of your image. For simple drawings, this isn’t generally a problem. But add in more advanced features, such as filters, and the output of the browsers begins to diverge.** | Unfortunately this method does come with one big drawback – though it’s a problem that diminishes every year. Because you are relying on your browser’s rendering engine to draw each object in your image, you no longer have complete control over the appearance of your image. For simple drawings, this isn’t generally a problem. But add in more advanced features, such as filters, and the output of the browsers begins to diverge.** | ||
- | Que vient faire la sécurité dans une image SVG, vous demandez-vous ? Imaginez que beaucoup de plateformes de réseaux sociaux, forums et autre sites Web, vous laisseront télécharger votre propre fichier SVG, ce qui l'exposera | + | Que vient faire la sécurité dans une image SVG, vous demandez-vous ? Imaginez que beaucoup de plateformes de réseaux sociaux, forums et autre sites Web, vous laisseront télécharger votre propre fichier SVG, puis l'exposer |
- | Malheureusement, | + | Malheureusement, |
**Text rendering is a particularly significant problem. If the person viewing the image doesn’t have the same font installed on their machine that you used to create the document in the first place, it will be replaced with a different font. In HTML, this can be annoying, but usually the browser adjusts the page layout a little and no real harm is done. In an image format, however, it can be much more of a problem. Consider something like a comic strip: if the text is rendered at the wrong size it might not fit the speech bubbles; if it’s rendered in a different font it could change the feel of the narrative entirely. For this reason, I post all my comic strips as PNG or JPEG images, and link to the SVG files separately where I want to make the source files available for people to download. | **Text rendering is a particularly significant problem. If the person viewing the image doesn’t have the same font installed on their machine that you used to create the document in the first place, it will be replaced with a different font. In HTML, this can be annoying, but usually the browser adjusts the page layout a little and no real harm is done. In an image format, however, it can be much more of a problem. Consider something like a comic strip: if the text is rendered at the wrong size it might not fit the speech bubbles; if it’s rendered in a different font it could change the feel of the narrative entirely. For this reason, I post all my comic strips as PNG or JPEG images, and link to the SVG files separately where I want to make the source files available for people to download. | ||
Ligne 31: | Ligne 31: | ||
The third approach is essentially another way of linking to an SVG file, but this time it uses the < | The third approach is essentially another way of linking to an SVG file, but this time it uses the < | ||
- | Le rendu du texte est particulièrement problématique. | + | Le rendu de texte est particulièrement problématique. |
- | La troisième approche est en gros une autre façon de faire le lien avec un ficher SVG, mais, cette fois, elle utilise l' | + | La troisième approche est en gros une autre façon de faire le lien avec un ficher SVG, mais, cette fois, elle utilise l' |
**The last approach is a relatively recent option. For years, SVG was neglected by the web developer community, largely because Microsoft refused to support it in earlier versions of Internet Explorer, at a time when it commanded the majority share of the market. But with later releases, Microsoft softened their stance, adding SVG support and paving the way for SVG to be promoted to a first-class citizen in the world of HTML5. Now, you can put a chunk of SVG code directly into your HTML and it will just work. And if you’re hand-coding your SVG, you no longer have to concern yourself with the complexities of namespaces in XML – just use the SVG tags in the same way as you would HTML. | **The last approach is a relatively recent option. For years, SVG was neglected by the web developer community, largely because Microsoft refused to support it in earlier versions of Internet Explorer, at a time when it commanded the majority share of the market. But with later releases, Microsoft softened their stance, adding SVG support and paving the way for SVG to be promoted to a first-class citizen in the world of HTML5. Now, you can put a chunk of SVG code directly into your HTML and it will just work. And if you’re hand-coding your SVG, you no longer have to concern yourself with the complexities of namespaces in XML – just use the SVG tags in the same way as you would HTML. | ||
With this last method, the SVG is a direct part of your web page, so writing code to manipulate the image is much simpler than with the < | With this last method, the SVG is a direct part of your web page, so writing code to manipulate the image is much simpler than with the < | ||
+ | |||
+ | La dernière approche est une option relativement récente. Pendant des années, SVG avait été négligée par la communauté des développeurs du Web, en grande partie parce que Microsoft refusait de la supporter dans les plus anciennes versions d' | ||
+ | |||
+ | Avec cette dernière méthode, le SVG est un élément direct de votre page Web ; aussi, l' | ||
**Enough theory, let’s put it into practice. Next month, I’ll describe how to use < | **Enough theory, let’s put it into practice. Next month, I’ll describe how to use < | ||
Ligne 44: | Ligne 48: | ||
I covered this dialog way back in part 12 of this series, but, for the purposes of creating a PNG to use online, you can ignore many of the options. You do need to decide what to export using the buttons at the top: usually this will be the entire page, the entirety of your drawing (which could be larger or smaller than the page), or a rectangle that encompasses the currently selected objects. I’ve chosen to export the whole page, as I want to include a little bit of blank space around my circle.** | I covered this dialog way back in part 12 of this series, but, for the purposes of creating a PNG to use online, you can ignore many of the options. You do need to decide what to export using the buttons at the top: usually this will be the entire page, the entirety of your drawing (which could be larger or smaller than the page), or a rectangle that encompasses the currently selected objects. I’ve chosen to export the whole page, as I want to include a little bit of blank space around my circle.** | ||
+ | |||
+ | Assez de théorie ! Passons à la pratique. Le mois prochain, je décrirai comme utiliser < | ||
+ | |||
+ | Exportons-la comme image PNG par la ligne de menu Fichier > Exporter au format PNG… Ceci ouvre un dialogue dans lequel régler les détails de l' | ||
+ | |||
+ | J'ai expliqué ce dialogue dans la partie 12 de la série, mais, pour les besoins de la création d'un PNG à utiliser en ligne, vous pouvez ignorer la plupart des options. Vous devez absolument décider ce que vous exportez en utilisant les boutons du haut : habituellement, | ||
**Now comes the most important decision: how big do you want your image to be? This is set in the Image Size section, by adjusting the image dimensions or dpi (dots per inch). For web use, you can generally ignore the dpi option and go straight for setting the width and height in pixels. If you’re creating an image for a profile picture or banner ad, you’ll usually be told the dimensions your graphic must be. Note, however, that you can’t set these fields independently, | **Now comes the most important decision: how big do you want your image to be? This is set in the Image Size section, by adjusting the image dimensions or dpi (dots per inch). For web use, you can generally ignore the dpi option and go straight for setting the width and height in pixels. If you’re creating an image for a profile picture or banner ad, you’ll usually be told the dimensions your graphic must be. Note, however, that you can’t set these fields independently, | ||
The last setting required is the filename to export to. Click the Export As… button and navigate to your destination folder in the file selector. Enter a filename in the selector, making sure it ends in “.png”, and then use the file selector’s Save button to return your selected location and name to the export dialog. Despite the name of the button, this won’t have saved a PNG file anywhere; it’s just saved the export location. In order to actually save the file, you have to click the Export button.** | The last setting required is the filename to export to. Click the Export As… button and navigate to your destination folder in the file selector. Enter a filename in the selector, making sure it ends in “.png”, and then use the file selector’s Save button to return your selected location and name to the export dialog. Despite the name of the button, this won’t have saved a PNG file anywhere; it’s just saved the export location. In order to actually save the file, you have to click the Export button.** | ||
+ | |||
+ | C'est là qu'il faut prendre la décision la plus importante : quelle taille voulez-vous donner à votre image ? Elle est définie dans la section Taille de l' | ||
+ | |||
+ | Le dernier réglage vous demande le nom du fichier vers lequel exporter. Cliquez sur le bouton Exporter sous… et naviguer jusqu' | ||
**You should now have a PNG file on disk that can be uploaded to just about any site that accepts user images. If you want to use it in your own HTML page, that’s easy too. If you’re already familiar with writing HTML then you almost certainly know how to link to your image. But if you’ve never written a line of HTML in your life, why not give it a try now – it’s not as tricky as you might think. In a text editor type the code shown below. | **You should now have a PNG file on disk that can be uploaded to just about any site that accepts user images. If you want to use it in your own HTML page, that’s easy too. If you’re already familiar with writing HTML then you almost certainly know how to link to your image. But if you’ve never written a line of HTML in your life, why not give it a try now – it’s not as tricky as you might think. In a text editor type the code shown below. | ||
Modify the “circle.png” string to suit the filename of your own PNG, and save the document into the same directory as the exported image, making sure to give the filename an extension of “.html”. Open the web browser of your choice, press CTRL-O to open the file selector, and load your HTML file. You should see a text heading with your PNG image displayed below it.** | Modify the “circle.png” string to suit the filename of your own PNG, and save the document into the same directory as the exported image, making sure to give the filename an extension of “.html”. Open the web browser of your choice, press CTRL-O to open the file selector, and load your HTML file. You should see a text heading with your PNG image displayed below it.** | ||
+ | |||
+ | Maintenant, vous devriez avoir un fichier PNG sur le disque qui peut être téléversé sur n' | ||
+ | |||
+ | Remplacez la chaîne « string.png » par le nom du fichier de votre propre PNG et enregistrez le document dans le même répertoire que l' | ||
**That wasn’t too tricky, was it? Linking directly to an SVG file is just as simple. If your original Inkscape file isn’t in the same directory as the HTML file, use File > Save a Copy… to put a copy of it there. When you look in the directory you should now see your HTML file, your exported PNG, and an SVG file. To get the latter to appear in your web page, just add the following lines below the existing image link: | **That wasn’t too tricky, was it? Linking directly to an SVG file is just as simple. If your original Inkscape file isn’t in the same directory as the HTML file, use File > Save a Copy… to put a copy of it there. When you look in the directory you should now see your HTML file, your exported PNG, and an SVG file. To get the latter to appear in your web page, just add the following lines below the existing image link: | ||
Ligne 62: | Ligne 80: | ||
<img src=" | <img src=" | ||
+ | |||
+ | Ce n' | ||
+ | |||
+ | < | ||
+ | |||
+ | <img src=" | ||
+ | |||
+ | Sauvegardez le fichier, passez sur votre navigateur et pressez F5 pour recharger la page. Vous devriez voir à la fois l' | ||
+ | |||
+ | <img src=" | ||
**Another press of F5 in the browser and you should find that both images are the same size. But what if we wanted them both to be larger? Try setting a width attribute on both of them, with a value of 1000 or more. Notice how blocky the PNG becomes, whilst the SVG is still rendered as smoothly as possible. That’s the main advantage of using an SVG file in a web page instead of a PNG. | **Another press of F5 in the browser and you should find that both images are the same size. But what if we wanted them both to be larger? Try setting a width attribute on both of them, with a value of 1000 or more. Notice how blocky the PNG becomes, whilst the SVG is still rendered as smoothly as possible. That’s the main advantage of using an SVG file in a web page instead of a PNG. | ||
Ligne 78: | Ligne 106: | ||
</ | </ | ||
+ | |||
+ | Un autre appui sur F5 dans le navigateur et vous devriez voir que les deux images ont la même taille. Mais que se passe-t-il si vous voulez que les deux images soient plus grandes ? Essayez de paramétrer un attribut de largeur pour chacune, avec une valeur de 1000 ou plus. Notez comme le PNG devient grossier, alors que le rendu du SVG est toujours aussi lissé que possible. C'est l' | ||
+ | |||
+ | La liaison à une image via la balise <img> est une manière classique d' | ||
+ | |||
+ | < | ||
+ | |||
+ | body { | ||
+ | |||
+ | background: url(" | ||
+ | | ||
+ | background-size: | ||
+ | |||
+ | } | ||
+ | |||
+ | </ | ||
**Reload the page to see the result. As a rule, modern browsers will let you use an SVG image wherever a raster is allowed. But although the browser might be happy to do that, many websites still only let you upload pure raster formats such as PNG, GIF and JPEG. If you write your own HTML you have full control over what formats to use, but if you’re trying to upload an image to a third party site you may find your options limited. If you can use an SVG, though, I encourage you to do so. Only by ever more SVG content making its way online will browser vendors have an incentive to provide better support for the format, and the SVG working group have a chance to introduce more of the new features that would make this useful format even better.** | **Reload the page to see the result. As a rule, modern browsers will let you use an SVG image wherever a raster is allowed. But although the browser might be happy to do that, many websites still only let you upload pure raster formats such as PNG, GIF and JPEG. If you write your own HTML you have full control over what formats to use, but if you’re trying to upload an image to a third party site you may find your options limited. If you can use an SVG, though, I encourage you to do so. Only by ever more SVG content making its way online will browser vendors have an incentive to provide better support for the format, and the SVG working group have a chance to introduce more of the new features that would make this useful format even better.** | ||
+ | |||
+ | Rechargez la page pour voir le résultat. La règle est que les navigateurs modernes vous laisseront utiliser une image SVG là où un bitmap est autorisé. Mais, bien que le navigateur puisse être heureux de le faire, beaucoup de sites Web ne vous laissent télécharger que de purs formats bitmap comme PNG, GIF ou JPEG. Si vous écrivez votre propre HTML, vous disposez du contrôle total sur les formats à utiliser, mais si vous essayez de télécharger une image sur le site d'un tiers, vous pourriez être limité dans vos options. Cependant, si vous pouvez utiliser un SVG, je vous encourage à le faire. Ce n'est qu'en augmentant le contenu SVG en ligne que les fournisseurs de navigateurs seront incités à fournir un meilleur support pour le format, et le groupe de travail SVG aura l' |
issue133/inkscape.1528441328.txt.gz · Dernière modification : 2018/06/08 09:02 de d52fr