![]() |
#1 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,251
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
|
Help with calibre Image quantize method, please
In the past week, a couple of Pocketbook users with Linux machines have reported a problem with my Copy Cover plugin. The problem is with the format of the images being produced. PBs needs them to be greyscale BMP at 4BPP (maybe 8BPP also OK?). However, on the 2 Linux machines the BMPs come out as greyscale 24BPP - which PBs won't use.
A sample of 2 users is not really enough to draw conclusions but testing on my WinXP PC correctly produces greyscale BMPs with 4BPP. I don't know if this is just dumb luck or whether there is something different about images produced on Windows than on Linux. I've also had the plugin beta-tested by a user with a Pocketbook903. She had no problems, but I suspect she was also a Windows user (still to confirm). Am I missing something obvious? I need to find a method which works on Win/Linux/OSX. The code I've been using since Jan 2011 is along these lines: Code:
from calibre.utils.magick import Image from calibre.utils.magick.draw import save_cover_data_to dest_path = r'/fullpath/to/device/imagedir/calibre_cover.bmp' cdata = self.db.cover(book_id, index_is_id=False, as_path=False) rescale = (600, 800) img = Image() img.load(cdata) img.size = rescale img.quantize(number_colors=16, colorspace='GRAYColorspace') save_cover_data_to(img, dest_path) I've tried various combinations, including not using img.quantize at all, but instead using the grayscale=True parameter of save_cover_data_to. However, the only combination I found which created 4BPP BMPs on my PC was the one above. All other reader models supported by the plugin, Sony/Kindle/Nook, are happy to receive colour jpg/png so a simple save_cover_data_to(cdata, dest_path, resize_to=rescale) suffices - no quantize necessary. As a non-Linux user, the following doesn't mean a lot to me but this is how each of the 2 Linux users described their setup
|
![]() |
![]() |
![]() |
#2 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,353
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Try
image.type = 'GrayscaleType' and then dont use save_cover_data_to, instead directly do image.save(path) instead of using quantize, though in imagemagick, there is no easy way to force the output to be a particular image sub-type. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,353
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Here's what it should look like:
image.type = 'GrayscaleType' image.save(path, 'BMP3') On my linux machine that produces an 8-bit bmp grayscale image |
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,251
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
|
OK, I'll create a beta version with that code and hope one of the Linux users will test it for me.
I'll report back with the outcome. Thank you for the fast reply ![]() |
![]() |
![]() |
![]() |
#5 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,251
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
|
Quote:
Just in case this may prompt any further ideas, the first Linux user had modified his own version of the plugin zip with Code:
save_cover_data_to(img, dest)
os.system("/usr/bin/convert - colors 8 %s %s" % (dest, dest))
|
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,353
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Hmm well them I'm at a loss. I dont see a method in the imagemagick api to set the number of colors,other than quantize, and you say that doesn't work.
|
![]() |
![]() |
![]() |
#7 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,251
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
|
Quote:
Whether it's always OK for Windows and always not-OK for Linux, I don't know. Based on previous feedback (or lack thereof) I suspect there are very few Pocketbook users of this plugin and even less who also use Linux, so I'll leave as-is and change the documentation accordingly. Thanks for trying ![]() |
|
![]() |
![]() |
![]() |
#8 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,353
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
One more try:
Code:
im.quantize(16, 'GRAYColorspace') im.type='PaletteType' im.save('t.bmp', 'BMP3') |
![]() |
![]() |
![]() |
#9 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,251
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
|
Quote:
![]() I'll PM the Linux user and report back when I have some results. Have a good weekend. ![]() |
|
![]() |
![]() |
![]() |
#10 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,251
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
|
Just a note to say that your suggestion worked well for the beta tester with a PB603 and Ubuntu.
![]() Let's hope I didn't break it for other PB users... |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Setting up Calibre for email-not Gmail method. | Tight | Calibre | 1 | 01-04-2012 03:44 PM |
image dans Calibre | morapat | Software | 0 | 08-15-2011 04:34 AM |
Calibre, RTF and image conversion | JasonPaulClaire | Calibre | 10 | 01-03-2011 03:18 PM |
What is your method of organizing ebooks on your JB? Calibre? | jerrywojo | Ectaco jetBook | 7 | 07-10-2010 04:09 PM |
Cover image going odd in Calibre | fading | Calibre | 6 | 10-05-2009 01:27 PM |