![]() |
#1 |
Obsessively Dedicated...
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,170
Karma: 34962952
Join Date: May 2011
Location: JAPAN (US expatriate)
Device: Sony PRS-T2, ADE on PC
|
Need Example SVG wrapper including caption
I am having trouble beating this into my weary brain. Sometimes it feels like the W3C site is speaking Greek, and I ain't Greek.
I've been using svg wrappers for just the image for quite a while. Now I want to try adding a caption. Would someone be so kind as to post a code example of a simple svg wrapper (with png or jpg image) that has a simple caption at the bottom? I don't want to get into rotating or any of the other Mardi Gras stuff right now ![]() I'll even save some of my Halloween candy for you ![]() Last edited by GrannyGrump; 11-04-2013 at 03:40 AM. |
![]() |
![]() |
![]() |
#2 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,215
Karma: 11695105
Join Date: Jul 2012
Device: Kobo Forma, Nook
|
I see you have learned nothing in a year and 9 months!
![]() https://www.mobileread.com/forums/sho...d.php?t=166836 The last I recall this "image and caption" being brought up was in this topic, with RbnJrg's (non-SVG) code: https://www.mobileread.com/forums/sho...d.php?t=223178 Doing something with HTML+CSS would probably have slightly better support/compatability/convertability (I don't know how well something like Calibre would handle converting a slightly more complex SVG?). Although I would be interested in an SVG solution as well. I know I am slacking in my SVG learning. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
Be aware that RbnJrg uses height: 100% for body and HTML. That can have unexpected results on Sony readers, sometimes even blocking the next button. It might also happen on other readers, but at least on the TRS-1.
|
![]() |
![]() |
![]() |
#4 |
Color me gone
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,089
Karma: 1445295
Join Date: Apr 2008
Location: Central Oregon Coast
Device: PRS-300
|
If you wrap them both together, then a Sony will see them as one block. If they are oversize, then my PRS-300 displays it also on the following page, overlapping the text.
|
![]() |
![]() |
![]() |
#5 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,450
Karma: 5738999
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
In your .css stylesheet, write the following: Code:
html { height: 100%; margin: 0; } body { height: 100%; margin: 0; } #container { height: 85%; } .img_caption { height: 15%; text-align:center; margin-top: 10px; font-weight: bold; } p { text-align: justify; text-indent: 1em; font-size: 1em; margin-bottom: 1em; } Code:
<body> <div id="container"> <svg xmlns="http://www.w3.org/2000/svg" height="100%" preserveAspectRatio="xMidYMid meet" version="1.1" viewBox="0 0 248 310" width="100%" xmlns:xlink="http://www.w3.org/1999/xlink"> <image height="310" width="248" xlink:href="../Images/Obama.jpg"></image> </svg> </div> <div class="img_caption"> Barak Obama<br /> President of the United States of America </div> </body> ![]() Below I attach screenshots on my ADE and the respective ePub. Regards Rubén |
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
Like I said, that solution does not work on all readers and can even block your reader from turning the page. YMMV.
|
![]() |
![]() |
![]() |
#7 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,470
Karma: 13095790
Join Date: Aug 2007
Location: Grass Valley, CA
Device: EB 1150, EZ Reader, Literati, iPad 2 & Air 2, iPhone 7
|
It is also legal and quite possible to add text using SVG itself which will make the caption part of the image frame itself.
Dale |
![]() |
![]() |
![]() |
#8 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,215
Karma: 11695105
Join Date: Jul 2012
Device: Kobo Forma, Nook
|
Yes, this is what I believe GrannyGrump was initially asking for. Anyone have any examples of this? I don't recall ever running into any in all of these "image + caption" threads.
|
![]() |
![]() |
![]() |
#9 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,450
Karma: 5738999
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
1. Caption inside the svg image wrapper: Code:
<body> <div id="container"> <svg xmlns="http://www.w3.org/2000/svg" height="100%" preserveAspectRatio="xMidYMid meet" version="1.1" viewBox="0 0 248 310" width="100%" xmlns:xlink="http://www.w3.org/1999/xlink"> <image height="310" width="248" xlink:href="../Images/Obama.jpg"></image> </svg> <svg xmlns="http://www.w3.org/2000/svg" version="1.1"> <text x="33%" y="95%" fill="red">Barak Obama</text> </svg> </div> </body> Code:
<body> <div id="container"> <svg xmlns="http://www.w3.org/2000/svg" height="100%" preserveAspectRatio="xMidYMid meet" version="1.1" viewBox="0 0 248 310" width="100%" xmlns:xlink="http://www.w3.org/1999/xlink"> <image height="310" width="248" xlink:href="../Images/Obama.jpg"></image> </svg> </div> <svg xmlns="http://www.w3.org/2000/svg" version="1.1"> <text x="40%" y="20" fill="black">Barak Obama</text> </svg> </body> Regards Rubén |
|
![]() |
![]() |
![]() |
#10 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,450
Karma: 5738999
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
That solution works for ADE. But I don't know if it works for the Sony, Nook, Kobo, etc. devices (I only have a Kindle). Perhaps, trial and error is the only way to know if the procedure is suitable for those ereaders.
|
![]() |
![]() |
![]() |
#11 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 266
Karma: 724240
Join Date: Aug 2013
Device: KyBook
|
I have noticed that several e-Readers on the iPhone suffer from next-page blockage if using a CSS body height of 100%. Sometimes even to the point that you cannot go back too
EDIT: Almost forgot the most important thing. You are not limited to using pixel size for the image dimension, you can also use percentages. If you set the viewbox to the exact size of the image and then height and width of the svg container to 100%, it will fit things nicely within the page when positioning the svg elements in the container. Centering is done via separate anchor attribute. See below example for an svg with embedded caption. Image is scaled down to 95% height, the width will automatically adjust because "preserveAspectRatio" prevents the image from distorting and also controls the alignment within the image container. The reduction in height will place the image container vertically aligned to top. So leave the width at 100% for horizontal centering. Code:
<svg xmlns="http://www.w3.org/2000/svg" height="100%" preserveAspectRatio="xMidyMid meet" version="1.1" viewBox="0 0 640 960" width="100%" xmlns:xlink="http://www.w3.org/1999/xlink"> <image height="95%" width="100%" xlink:href="../Images/fullpage.png"/> <text text-anchor="middle" font-size="xx" x="50%" y="98%" fill="black">Caption</text> </svg> Code:
<svg xmlns="http://www.w3.org/2000/svg" height="100%" preserveAspectRatio="xMidyMid meet" version="1.1" viewBox="0 0 640 960" width="100%" xmlns:xlink="http://www.w3.org/1999/xlink"> <image height="95%" width="100%" xlink:href="../Images/fullpage.png"/> <a xlink:href="someplace else"><text text-anchor="middle" font-size="xx" x="50%" y="98%">Caption</text></a> </svg> Last edited by At_Libitum; 11-04-2013 at 02:10 PM. |
![]() |
![]() |
![]() |
#12 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,470
Karma: 13095790
Join Date: Aug 2007
Location: Grass Valley, CA
Device: EB 1150, EZ Reader, Literati, iPad 2 & Air 2, iPhone 7
|
Quote:
Dale |
|
![]() |
![]() |
![]() |
#13 | |
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,466
Karma: 17555555
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
Quote:
|
|
![]() |
![]() |
![]() |
#14 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,470
Karma: 13095790
Join Date: Aug 2007
Location: Grass Valley, CA
Device: EB 1150, EZ Reader, Literati, iPad 2 & Air 2, iPhone 7
|
|
![]() |
![]() |
![]() |
#15 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,450
Karma: 5738999
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
Your solution is very elegant but regrettably, has one fail: it doesn't work in ADE ![]() So, the only solution I see is to employ a image with a blank space below and to add the caption in that blank space. See the following: 1. In the .css stylesheet: Code:
p { text-align: justify; text-indent: 1em; font-size: 1em; margin-bottom: 1em; } Code:
<body> <div> <svg xmlns="http://www.w3.org/2000/svg" height="100%" preserveAspectRatio="xMidYMid meet" version="1.1" viewBox="0 0 248 340" width="100%" xmlns:xlink="http://www.w3.org/1999/xlink"> <image height="340" width="248" xlink:href="../Images/Obama.jpg"></image> <text text-anchor="middle" x="124" y="325" fill="red" style="font-weight: bold; font-size: 15px">Barak Obama</text> </svg> </div> </body> To center the text I used the property text-anchor="middle" (as you well pointed out, thank you very much) and a "x" value of 124 (pixels) that is, the half of the image width. And this time I didn't use a height of 100% for the html and body tag ![]() ![]() ![]() Regards Rubén Last edited by RbnJrg; 11-04-2013 at 03:15 PM. |
|
![]() |
![]() |
![]() |
Tags |
image & caption together, image caption, svg text, svg wrapper caption |
Thread Tools | Search this Thread |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Applescript Wrapper Application for Kindlegen | pdurrant | Kindle Formats | 50 | 02-18-2020 01:16 AM |
Adding an SVG Wrapper | ghostyjack | Sigil | 16 | 06-15-2013 05:13 AM |
An Issue about a SVG wrapper | RbnJrg | Kindle Formats | 29 | 06-10-2013 08:11 PM |
Keeping caption and illustration together | John123 | ePub | 4 | 12-02-2012 09:19 AM |
Center Image and Caption | SamL | ePub | 11 | 08-12-2011 09:27 AM |