View Single Post
Old 10-23-2024, 05:19 PM   #530
philja
Addict
philja will become famous soon enoughphilja will become famous soon enoughphilja will become famous soon enoughphilja will become famous soon enoughphilja will become famous soon enoughphilja will become famous soon enough
 
Posts: 282
Karma: 516
Join Date: Nov 2015
Location: Europe EEC
Device: Kindle Fire HD6 & HD8
Quote:
Originally Posted by KevinH View Post
But I doubt you want to convert width="50%" to width="50" as 50 pixels is much different from 50% of the screen.

Much more likely, is to remove the width attribute and replace it with either a new "class" attribute or even an inline style attribute such as style="width:50%;" or something else that sets the limit for the width of the resulting image.
Which is essentially what I did. I hacked together a regex FIND:

<img\s+(alt="Image .+?")\s+(src="../Images/image\d+\.gif")\s+width="(\d+)%"\s*/>

[ this also worked <img\s+(alt="[^"]*")\s+(src="[^"]*")\s+width="(\d+)%"\s*/> ]

with a REPLACE:

<img class="w\3" \2 \1/>

[This put the alt entry at the end keeping it out of the way visually when checking images later.]

Since many of the images had width=50%, I started with an additional CSS class in the style sheet :

.w50 {height: auto;width: 50%}

and then did a find/replace one at a time. This was a little tedious but pretty quick. When I came to an image with a different width %, if I then decided it would be better to keep it at that width, I just created an additional CSS style entry.

Afterwards, I was curious to find out why all the image entries were not displayed as errors by the epubcheck plugin. So I redid the epub3 conversion and investigated. I also had a look at the log and saw that it had a line:

Code:
 "message" : "Error while parsing file: value of attribute \"width\" is invalid; must be an integer",
    "additionalLocations" : 50,
I think that if some indication of the total number of errors would be displayed by the epubcheck plugin, it would be helpful to those authors who don't know how to access the log.

Last edited by philja; 10-23-2024 at 05:27 PM.
philja is offline   Reply With Quote