Hi Alex,
On 09/09/2010 11:35 PM, Alex Busenius wrote:
Hi,
Currently we simply copy-paste the attributes into the generated HTML,
which makes the syntax ambiguous. E.g. it is possible to write something
like
[[image:logo.jpg||width="100px" height="50%" style="width: 45%;
height:
100px"]]
I don't understand why do you say the syntax is ambiguous. I guess you
consider XHTML syntax ambiguous too, because:
<img src="logo.jpg" alt="logo" width="100px"
height="50%" style="width:
45%; height: 100px" />
is perfectly valid. You can specify image size either using the
attributes or using CSS (be it in-line, though the style attribute, or
in a style sheet). CSS (both in-line and style sheet) always takes
precedence over the size attributes. Thus in your example, the final
image size in the browser is 45% x 100px. Note that there is a
difference in what you can specify with the size attributes and what you
can specify with CSS: width/height attributes accept only pixels or
percent, so CSS (i.e. the style attribute) is more powerful.
Using the size information for resizing pictures sound interesting, but
regarding the example above:
What will happen if the user specifies width or height
in percent?
If the unit (
http://www.w3schools.com/css/css_units.asp ) of
width/height is not pixel then I continue as if the width/height hasn't
been specified. For instance, if image width/height limit is set to
800x600 in configuration then:
width:30%; height:3cm => ?width=800&height=600&keepAspectRatio=true
width:70px; height:3in => ?width=70
width:6em; height:20px => ?height=20
width:35px; height:15px => ?width=35&height=15
What if pixel and percent numbers are mixed (e.g.
width is in px and
height in %)?
Only the dimension expressed in pixels is used. Width and height are
"read" from image parameters independent of each other.
What takes precedence, width attribute or CSS style
attribute?
Always the CSS (be it in-line or from a style sheet).
Will the size information XWiki uses to resize images
be the same as
various browsers use to display the image?
Most of the time the image will be resized just once, on the server.
There are some cases though when the image will be resized both on the
server and on the client (by the browser). For instance:
* if width and height are not expressed in pixels then the server will
limit the image size based on configuration and the browser will resize
the image based on specified width/height
* if one of the dimensions is expressed in pixels and the other in
percent (or any other unit different than pixel) then the server will
scale the image using the pixel dimension and the browser will adjust
the other based on the specified value.
* if width and height are specified in pixels but there is an external
style sheet that enforces a different image size then the server will
scale the image based on the specified width/height and the browser will
resize the returned image based on the external style sheet.
In general, I think copy-pasting the attributes is bad (esp. from
security PoV). I'd prefer having a fixed set of supported attributes
(subset of HTML/CSS) that are handled in a fully deterministic way. This
would for example allow to specify how exactly the width information is
parsed and transform the example above into a non-ambiguous form on save.
I think you are referring to the XHTML renderer here, but my change
targets all the renderers. A renderer doesn't know how to assemble the
URL for an attachment or a document so it asks the WikiModel. Thomas and
I discussed about adding a:
String getImageURL(String documentName, String fileName, Map<String,
String> parameters)
method to WikiModel, that can be used by any renderer. XWikiWikiModel
(our implementation) will look at the passed parameters map and if image
width/height is specified them it will add this information to the query
string of the attachment download URL. The fact that we look for the
"width", "height" and "style" parameters is a convention.
It's not
related to HTML. The fact that the style image parameter contains CSS is
also unrelated to HTML (CSS can be used on other types of structured
content).
Regarding copy-pasting custom parameters from XWiki syntax to the
rendered HTML (by the XHTML renderer) I don't have a strong opinion. I
don't see why it is bad from security PoV. I'll let Thomas and Vincent
comment on this.
Since your change would introduce parsing for the parameters, it might
be a good point to start going into this direction, WDYT?
This needs to be discussed in a separate thread.
Thanks for your feedback,
Marius
Thanks,
Alex
On 09/08/2010 10:40 PM, Marius Dumitru Florea wrote:
Hi devs,
Currently the image plugin [1] allows us to create image thumbnails by
specifying the image width and/or height in the query string of the
image attachment download URL:
/xwiki/bin/download/Spage/Page/image.jpg?width=100
I propose that we:
(A) Use the image width and/or height (when they are specified in the
image syntax using pixel unit) to resize the image on the server side.
For instance:
[[image:logo.jpg||width="100px"]]
will be linked to
/xwiki/bin/download/Spage/Page/logo.jpg?width=100
and
[[image:logo.jpg||style="height: 50px; width: 70px"]]
will be linked to
/xwiki/bin/download/Spage/Page/logo.jpg?width=70&height=50
The image plugin also accepts a quality parameter that controls the
compression quality when encoding jpeg images. The default value of this
parameter (i.e. when not specified in the URL) is configurable. I
propose we use 0.3 by default, 1 representing the best quality.
(B) Add the ability to limit the image dimensions (preserving aspect
ratio) when the image width and/or height are not specified in the image
syntax (or when they are not using pixel unit). The width and height
limit will be configurable and -1 by default (i.e. no limitation). For
instance:
image:logo.jpg
will be linked to
/xwiki/bin/download/Spage/Page/logo.jpg?width=1024
when width limit is 1024, and to
/xwiki/bin/download/Spage/Page/logo.jpg?width=1024&height=768&keepAspectRatio=true
when width limit is 1024 and height limit is 768. Note that in this case
the image aspect ratio is preserved. The image is resized to best fit
the limits. If the user want to bypass the limit he has to specify the
image width/height in the image syntax.
I'm +1 for both (A) and (B). WDYT?
Thanks,
Marius
[1]
http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-core/src/main/…
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs