Vote #64007
未完了Add SVG support, like images
0%
説明
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 :
journals
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>
--------------------------------------------------------------------------------
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?
--------------------------------------------------------------------------------
Any news?
--------------------------------------------------------------------------------
+1
--------------------------------------------------------------------------------
You can display SVG image if you put full URL of the image:
<pre>!http://www.redmine.org/attachments/download/1042/ananas.svg!</pre>
!http://www.redmine.org/attachments/download/1042/ananas.svg!
--------------------------------------------------------------------------------
+1
patch for trunk.
* Show attached SVG (no direct download)
<pre>
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?
</pre>
* Insert attached SVG file in wiki pages, with a syntax near from "!!"
<pre>
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)
</pre>
--------------------------------------------------------------------------------
can this patch support the export to PDF function ( with image in the PDF file ) ?
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
The patches in note-6 from Jun NAITOH seem feasible.
--------------------------------------------------------------------------------
RFPDF is obsolete, even the author is migrating to Prawn: https://github.com/edwinmoss/rfpdf We should consider migrating too.
--------------------------------------------------------------------------------
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
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
This is really easy to implement. Is there any needed step still? Do the maintainers need a test unit for this?
--------------------------------------------------------------------------------
This is a really useful feature!
--------------------------------------------------------------------------------
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:
<pre>
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'
</pre>
command line:
<pre>
$ 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.
</pre>
--------------------------------------------------------------------------------
Karel Pičman wrote:
> You can display SVG image if you put full URL of the image:
>
> [...]
>
> !http://www.redmine.org/attachments/download/1042/ananas.svg!
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.
--------------------------------------------------------------------------------
+1
--------------------------------------------------------------------------------
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@.
<pre><code class="xml">
<?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>
</code></pre>
Maybe we have to generate all thumbnails in PNG or JPEG format to support SVG images.
--------------------------------------------------------------------------------
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.
<pre>
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
</pre>
<pre>
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
</pre>
--------------------------------------------------------------------------------
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:
<pre>
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!
</pre>
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:
<pre>
!https://my-domain.com/my-redmine/attachments/download/558/ananas.svg!
</pre>
--------------------------------------------------------------------------------
Admin Redmine さんが3年以上前に更新
- カテゴリ を Attachments_19 にセット
- 対象バージョン を Candidate for next major release_32 にセット