- if nil != coverId
- items = opfDoc.css('package manifest item')
- for i in items
- href = i['href']
- id = i['id']
- mimeType = i['media-type']
-
- if coverId == id
- entry = zipfile.find_entry(href)
+ if nil == coverId
+ coverId = "cover-image"
+ end
+
+ items = opfDoc.css('package manifest item')
+ for i in items
+ href = i['href']
+ id = i['id']
+ mimeType = i['media-type']
+
+ if coverId == id
+ entry = zipfile.find_entry(href)
+
+ if nil == entry
+ # Although the epub standard requires the path to be relative
+ # to the base of the epub (zip), some books encountered in the
+ # wild have been found to use a bath relative to the location
+ # of the opf file.
+ parts = opfPath.split('/')
+ opfBasePath = opfPath.split('/')[0..-2].join('/')
+ coverPath = opfBasePath + '/' + href
+ entry = zipfile.find_entry(coverPath)
+ end
+
+ if nil == entry
+ puts 'WARNING! Cover image "' + href + '" not found in file "' + @path + '".'
+ return nil
+ else