Feature #2047
openAdd SVG support, like images
0%
Description
It would be great if we could :
- Show attached SVG (no direct download)
- Insert an SVG file in wiki pages, with a syntax near from "!!"
Syntax proposal :
Wiki : °link/to/svg_file.svg°
HTML : <object data="link/to/svg_file.svg" width="100" height="100" type="image/svg+xml">Error</object>
Files
Related issues
Updated by Pierre Bertet about 16 years ago
Update (I forgot the dimensions) :
Wiki : °link/to/svg_file.svg(100x100)°
HTML : <object data="link/to/svg_file.svg" width="100" height="100" type="image/svg+xml">Error</object>
Updated by Oleg Lozinskij over 15 years ago
Pierre Bertet wrote:
Update (I forgot the dimensions) :
Wiki : °link/to/svg_file.svg(100x100)°
HTML : <object data="link/to/svg_file.svg" width="100" height="100" type="image/svg+xml">Error</object>
Exactly what I was looking for :)
It is already available?
Updated by Karel Pičman over 12 years ago
You can display SVG image if you put full URL of the image:
!http://www.redmine.org/attachments/download/1042/ananas.svg!
Updated by Jun NAITOH over 12 years ago
+1
patch for trunk.
- Show attached SVG (no direct download)
Index: app/models/attachment.rb =================================================================== --- app/models/attachment.rb (revision 10173) +++ app/models/attachment.rb (working copy) @@ -162,7 +162,7 @@ end def image? - !!(self.filename =~ /\.(bmp|gif|jpg|jpe|jpeg|png)$/i) + !!(self.filename =~ /\.(bmp|gif|jpg|jpe|jpeg|png|svg)$/i) end def thumbnailable?
- Insert attached SVG file in wiki pages, with a syntax near from "!!"
Index: app/helpers/application_helper.rb =================================================================== --- app/helpers/application_helper.rb (revision 10173) +++ app/helpers/application_helper.rb (working copy) @@ -572,7 +572,7 @@ # when using an image link, try to use an attachment, if possible if options[:attachments] || (obj && obj.respond_to?(:attachments)) attachments = options[:attachments] || obj.attachments - text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m| + text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png|svg))"(\s+alt="([^"]*)")?/i) do |m| filename, ext, alt, alttext = $1.downcase, $2, $3, $4 # search for the picture in attachments if found = Attachment.latest_attach(attachments, filename)
Updated by YT Wu over 12 years ago
can this patch support the export to PDF function ( with image in the PDF file ) ?
Updated by Jun NAITOH over 12 years ago
YT Wu wrote:
can this patch support the export to PDF function ( with image in the PDF file ) ?
No.
Because, RFPDF library is not supporting SVG file.
Updated by Evgeny Seliverstov almost 12 years ago
Jun NAITOH wrote:
patch for trunk.
Is there a chance to get this small patch in trunk? Manual patches to redmine files is not a best solution.
I think it can't break anything except a missed image in PDF.
Updated by Mischa The Evil almost 12 years ago
- Target version set to Candidate for next major release
The patches in note-6 from Jun NAITOH seem feasible.
Updated by Gabriel Mazetto over 11 years ago
RFPDF is obsolete, even the author is migrating to Prawn: https://github.com/edwinmoss/rfpdf We should consider migrating too.
Updated by Toshi MARUYAMA over 11 years ago
Gabriel Mazetto wrote:
RFPDF is obsolete, even the author is migrating to Prawn: https://github.com/edwinmoss/rfpdf We should consider migrating too.
RFPDF is maintained by Jun NAITOH.
https://github.com/naitoh/rfpdf
Updated by Adrien Crivelli over 11 years ago
We often use SVG images and would be glad to see them supported with the same syntax as any other images. I am in favor of implementing patch suggested in note 6.
Updated by Paulo Neves almost 11 years ago
This is really easy to implement. Is there any needed step still? Do the maintainers need a test unit for this?
Updated by Go MAEDA about 9 years ago
I tried Jun NAITOH's patch pasted on #2047#note-6 but thumbnails for SVG images are not properly generated on my environment.
- Redmine 3.1.1.devel.14638
- ImageMagick 6.8.9-8
- Mac OS X 10.9.5
error messages in development.log:
Creating thumbnail failed (pid 16631 exit 1): Command: 'convert' '/path/to/redmine/files/2015/10/151004112923_ananas.svg' -thumbnail '100x100>' '/path/to/redmine/tmp/thumbnails/40_6f1215c37c5a7abc38cc60463fac05df_100.thumb'
command line:
$ convert ananas.svg -thumbnail 100x100 convert: delegate failed `"rsvg-convert" -o "%o" "%i"' @ error/delegate.c/InvokeDelegate/1153. convert: unable to open image `/var/tmp/magick-16839ei4QFzFms7K4': No such file or directory @ error/blob.c/OpenBlob/2709. convert: unable to open file `/var/tmp/magick-16839ei4QFzFms7K4': No such file or directory @ error/constitute.c/ReadImage/540. convert: missing an image filename `100x100' @ error/convert.c/ConvertImageCommand/3184.
Updated by Silvio Knizek about 8 years ago
Karel Pičman wrote:
You can display SVG image if you put full URL of the image:
[...]
The problem with this is that you can't click on any hyperlinks embedded into the SVG. So for SVG a specific case would be more appropriate.
Updated by Go MAEDA almost 8 years ago
Current implementation of Redmine::Thumbnail.generate method creates thumbnail images in same format with original image. But ImageMagick convert command cannot make thumbnails in SVG format. The following is a result of convert ananas.svg -thumbnail 100x100 thumbnail.svg
.
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="100" height="100">
<g style="</svg>
Maybe we have to generate all thumbnails in PNG or JPEG format to support SVG images.
Updated by Keith Carangelo over 4 years ago
I was able to add thumbnail previews of images in SVG format by returning the original source file as the thumbnail instead of generating a new file. I also needed to add a width (width="100%"
) to the thumbnail image link to get the SVG to display.
diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 3affca0ba..0c204a88f 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -195,7 +195,7 @@ class Attachment < ActiveRecord::Base end def image? - !!(self.filename =~ /\.(bmp|gif|jpg|jpe|jpeg|png)$/i) + !!(self.filename =~ /\.(bmp|gif|jpg|jpe|jpeg|png|svg)$/i) end def thumbnailable? @@ -216,6 +216,12 @@ class Attachment < ActiveRecord::Base size = Setting.thumbnails_size.to_i end size = 100 unless size > 0 + + # For SVG format, simply return the file as the target + if is_svg? + return self.diskfile + end + target = File.join(self.class.thumbnails_storage_path, "#{id}_#{digest}_#{size}.thumb") begin @@ -242,6 +248,10 @@ class Attachment < ActiveRecord::Base Redmine::MimeType.is_type?('image', filename) end + def is_svg? + Redmine::MimeType.of(filename) == "image/svg+xml" + end + def is_diff? self.filename =~ /\.(patch|diff)$/i end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7a3a375c0..4059788e0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -268,7 +268,7 @@ module ApplicationHelper image_tag( thumbnail_path(attachment), :srcset => "#{thumbnail_path(attachment, :size => thumbnail_size * 2)} 2x", - :style => "max-width: #{thumbnail_size}px; max-height: #{thumbnail_size}px;" + :style => "width: 100%; max-width: #{thumbnail_size}px; max-height: #{thumbnail_size}px;" ), attachment_path( attachment
Updated by Gary Aitken almost 3 years ago
Should clicking on the thumbnail display the .svg?
With the mods mentioned above, I get the thumbnail ok, but clicking on the thumbnail displays the source.
Also, if I have two references in a note:
The local copy of ananas.svg should appear below here !https://my-domain.com/my-redmine/attachments/558/ananas.svg! The remote copy of ananas.svg should appear below here !http://www.redmine.org/attachments/download/1042/ananas.svg!
The first one does not display in the note, and the second one does.
Edit: adding the "download" element of the path causes it to work:
!https://my-domain.com/my-redmine/attachments/download/558/ananas.svg!
Updated by T H over 1 year ago
Just as an additional thought: I had success embedding a simple SVG file as an image with the “download url workaround”. However, when exporting the wiki page as PDF, the image is not included. So a full implementation of SVG support needs to consider exporting pages as well.
Updated by Go MAEDA 11 months ago
- Related to Feature #11998: PDF export svg support added