Project

General

Profile

Actions

Feature #2047

open

Add SVG support, like images

Added by Pierre Bertet over 15 years ago. Updated 10 months ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Attachments
Start date:
2008-10-18
Due date:
% Done:

0%

Estimated time:
Resolution:

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

ananas.svg (34.7 KB) ananas.svg Demo: this file will not be displayed, but directly downloaded Pierre Bertet, 2008-10-18 01:15

Related issues

Related to Redmine - Feature #11998: PDF export svg supportNew

Actions
Actions #1

Updated by Pierre Bertet over 15 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>

Actions #2

Updated by Oleg Lozinskij about 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?

Actions #3

Updated by Pierre Bertet almost 14 years ago

Any news?

Actions #4

Updated by Karel Pičman over 11 years ago

+1

Actions #5

Updated by Karel Pičman over 11 years ago

You can display SVG image if you put full URL of the image:

!http://www.redmine.org/attachments/download/1042/ananas.svg!

Actions #6

Updated by Jun NAITOH over 11 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)
    
Actions #7

Updated by YT Wu over 11 years ago

can this patch support the export to PDF function ( with image in the PDF file ) ?

Actions #8

Updated by Jun NAITOH over 11 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.

Actions #9

Updated by Evgeny Seliverstov about 11 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.

Actions #10

Updated by Mischa The Evil about 11 years ago

  • Target version set to Candidate for next major release

The patches in note-6 from Jun NAITOH seem feasible.

Actions #11

Updated by Gabriel Mazetto almost 11 years ago

RFPDF is obsolete, even the author is migrating to Prawn: https://github.com/edwinmoss/rfpdf We should consider migrating too.

Actions #12

Updated by Toshi MARUYAMA almost 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

Actions #13

Updated by Adrien Crivelli over 10 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.

Actions #14

Updated by Paulo Neves about 10 years ago

This is really easy to implement. Is there any needed step still? Do the maintainers need a test unit for this?

Actions #15

Updated by yp xiao about 9 years ago

This is a really useful feature!

Actions #16

Updated by Go MAEDA over 8 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.

Actions #17

Updated by Silvio Knizek over 7 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.

Actions #18

Updated by Zer Guz over 7 years ago

+1

Actions #19

Updated by Go MAEDA over 7 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.

Actions #20

Updated by Keith Carangelo about 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
Actions #21

Updated by Gary Aitken about 2 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!
Actions #22

Updated by T H 10 months 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.

Actions #23

Updated by Go MAEDA 3 months ago

Actions

Also available in: Atom PDF