Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Conversion

Notices

Reply
 
Thread Tools Search this Thread
Old 07-20-2011, 01:00 PM   #1
madeinlisboa
Enjoy Life
madeinlisboa began at the beginning.
 
Posts: 26
Karma: 10
Join Date: Jun 2011
Location: Portugal
Device: Kindle
Images to grayscale

I'm sorry if this is a dup, but I searched and found nothing.

Is it possible to change images to grayscale when a book is converted? In this case from CHM to MOBI. It would lower substantially the final size.
madeinlisboa is offline   Reply With Quote
Old 07-21-2011, 07:02 PM   #2
madeinlisboa
Enjoy Life
madeinlisboa began at the beginning.
 
Posts: 26
Karma: 10
Join Date: Jun 2011
Location: Portugal
Device: Kindle
Please, is my question senseless?
madeinlisboa is offline   Reply With Quote
Old 07-21-2011, 07:37 PM   #3
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,844
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
No, it isn't.
kovidgoyal is offline   Reply With Quote
Old 07-22-2011, 06:51 AM   #4
madeinlisboa
Enjoy Life
madeinlisboa began at the beginning.
 
Posts: 26
Karma: 10
Join Date: Jun 2011
Location: Portugal
Device: Kindle
And?....
madeinlisboa is offline   Reply With Quote
Old 07-22-2011, 07:25 AM   #5
DoctorOhh
US Navy, Retired
DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.
 
DoctorOhh's Avatar
 
Posts: 9,864
Karma: 13806776
Join Date: Feb 2009
Location: North Carolina
Device: Icarus Illumina XL HD, Nexus 7
Quote:
Originally Posted by kovidgoyal View Post
Quote:
Originally Posted by madeinlisboa View Post
Is it possible to change images to grayscale when a book is converted?
No, it isn't.
I've grouped things above so you'll understand the answer.
DoctorOhh is offline   Reply With Quote
Old 07-22-2011, 07:44 AM   #6
madeinlisboa
Enjoy Life
madeinlisboa began at the beginning.
 
Posts: 26
Karma: 10
Join Date: Jun 2011
Location: Portugal
Device: Kindle
First, I thought that mr. kovidgoyal was being ironic (his answer was right after my second question and it fitted perfectly), and now YOU are being ironic. What it the matter with you people in this forum?
madeinlisboa is offline   Reply With Quote
Old 10-30-2011, 09:53 AM   #7
scissors
Addict
scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.
 
Posts: 241
Karma: 1001369
Join Date: Sep 2010
Device: prs300, kindle keyboard 3g
Quote:
Originally Posted by madeinlisboa View Post
I'm sorry if this is a dup, but I searched and found nothing.

Is it possible to change images to grayscale when a book is converted? In this case from CHM to MOBI. It would lower substantially the final size.
Wouldn't this be useful for news recipes that grab lots of photos - which will only be displayed on B&W e-ink devices?

Could this command be added Kovid?

Last edited by scissors; 10-30-2011 at 01:11 PM.
scissors is offline   Reply With Quote
Old 11-01-2011, 02:26 PM   #8
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by scissors View Post
Wouldn't this be useful for news recipes that grab lots of photos - which will only be displayed on B&W e-ink devices?
I assume you are trying to save space?

Quote:
Could this command be added Kovid?
I've used ImageMagick in recipes (calibre.utils.magick import Image) to rotate images. I'm not familiar with how much of ImageMagick is supported in Calibre, but there are sepia tone and grayscale separation commands in ImageMagick that might already be supported?
Starson17 is offline   Reply With Quote
Old 11-01-2011, 03:30 PM   #9
scissors
Addict
scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.
 
Posts: 241
Karma: 1001369
Join Date: Sep 2010
Device: prs300, kindle keyboard 3g
Quote:
Originally Posted by Starson17 View Post
I assume you are trying to save space?
Exactly.

Quote:
Originally Posted by Starson17 View Post
I've used ImageMagick in recipes (calibre.utils.magick import Image) to rotate images. I'm not familiar with how much of ImageMagick is supported in Calibre, but there are sepia tone and grayscale separation commands in ImageMagick that might already be supported?
I'm only a thick windows user. I've never head of imagemagik. I managed to figure out calibre.utils.magick import Image needs the FROM command to import it. The recipe accepted this.

I went to an imagemagik sit and found the -colorspace command. I tried colorspace=gray but calibre gives errors.

Other commands seem to need actual filenames in the command line?

I'm not sure how much calibre uses and even how to implement what it does use.

Can you give a link to your rotate example - is it somewhere in the re-usable code section?
scissors is offline   Reply With Quote
Old 11-01-2011, 08:58 PM   #10
jackie_w
Grand Sorcerer
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 6,208
Karma: 16534692
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
Quote:
Originally Posted by scissors View Post
I went to an imagemagik sit and found the -colorspace command. I tried colorspace=gray but calibre gives errors.
Does colorspace='GRAYColorspace' work any better?
jackie_w is offline   Reply With Quote
Old 11-02-2011, 10:44 AM   #11
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by scissors View Post
I went to an imagemagik sit and found the -colorspace command. I tried colorspace=gray but calibre gives errors.
Did you implement it in a recipe and import as needed? My code for rotating images is in the sticky code thread of the recipe forum. You can see there how I used the rotate options.
Spoiler:
Code:
#Add these imports
from calibre.utils.magick import Image, PixelWand

    def postprocess_html(self, soup, first):
        #process all the images. assumes that the new html has the correct path
        for tag in soup.findAll(lambda tag: tag.name.lower()=='img' and tag.has_key('src')):
            iurl = tag['src']
            img = Image()
            img.open(iurl)
            width, height = img.size
            print 'img is: ', iurl, 'width is: ', width, 'height is: ', height 
            if img < 0:
                raise RuntimeError('Out of memory')
            pw = PixelWand()
            if( width > height ) :
                print 'Rotate image'
                img.rotate(pw, -90)
                img.save(iurl)
        return soup
Starson17 is offline   Reply With Quote
Old 11-02-2011, 02:39 PM   #12
scissors
Addict
scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.scissors ought to be getting tired of karma fortunes by now.
 
Posts: 241
Karma: 1001369
Join Date: Sep 2010
Device: prs300, kindle keyboard 3g
Thanks for the replies guys

both
colorspace='GRAYColorspace'
img.colorspace='GRAYColorspace'

compile. I added starson's code to the end of the Sun via google recipe.
Images rotate, but are still colour. :-(

I put the command in both IF statements to try and cover all bases, but nothing seems to happen.

Spoiler:
Code:
import urllib, re, mechanize
from calibre.web.feeds.recipes import BasicNewsRecipe
from calibre import __appname__
from calibre.utils.magick import Image, PixelWand

class GoogleReader(BasicNewsRecipe):
    title   = 'The Sun UK Via Google Reader2'
    
    #last updated 30/10/11 tidyied some stray classes

    cover_url = 'http://www.thesun.co.uk/img/global/new-masthead-logo.png'
     
    description = 'A Recipe for The Sun tabloid UK using the google reader recipe. You need to set up a gmail account solely for the reader, then subscribe to the suns RSS feeds at http://www.thesun.co.uk/sol/homepage...icle247949.ece'
    needs_subscription = True
    __author__ = ' Dave Asbury, davec, rollercoaster, Starson17'
    base_url = 'http://www.google.com/reader/atom/'
    oldest_article = 1
    max_articles_per_feed = 20
    get_options = '?n=%d&xt=user/-/state/com.google/read' % max_articles_per_feed
   # use_embedded_content = True

    masthead_url = 'http://www.thesun.co.uk/sol/img/global/Sun-logo.gif'
    #encoding = 'iso-8859-1'
    
    encoding = 'cp1252'
    remove_empty_feeds = True
    remove_javascript     = True
    no_stylesheets = True
    
    extra_css  = '''
	body{ text-align: justify; font-family:Arial,Helvetica,sans-serif; font-size:11px; font-size-adjust:none; font-stretch:normal; font-style:normal; font-variant:normal; font-weight:normal;}
                	 '''
    
    preprocess_regexps = [
    (re.compile(r'<div class="foot-copyright".*?</div>', re.IGNORECASE | re.DOTALL), lambda match: '')]
    
      
   
    keep_only_tags = [
                               dict(name='h1'),dict(name='h2',attrs={'class' : 'medium centered'}),
	           dict(name='div',attrs={'class' : 'text-center'}),
	           dict(name='div',attrs={'id' : 'bodyText'})
	           # dict(name='p')
	           ]
    remove_tags=[
	       #dict(name='head'),
	       dict(attrs={'class' : ['mystery-meat-link','ltbx-container','ltbx-var ltbx-hbxpn','ltbx-var ltbx-nav-loop','ltbx-var ltbx-url']}),
                           dict(name='div',attrs={'class' : 'cf'}),
	       dict(attrs={'title' : 'download flash'}),
                           dict(attrs={'style' : 'padding: 5px'})
	      
	       ]
    
   

    def get_browser(self):
        br = BasicNewsRecipe.get_browser(self)
        if self.username is not None and self.password is not None:
            request = urllib.urlencode([('Email', self.username), ('Passwd', self.password),
                                        ('service', 'reader'), ('accountType', 'HOSTED_OR_GOOGLE'), ('source', __appname__)])
            response = br.open('https://www.google.com/accounts/ClientLogin', request)
            auth = re.search('Auth=(\S*)', response.read()).group(1)
            cookies = mechanize.CookieJar()
            br = mechanize.build_opener(mechanize.HTTPCookieProcessor(cookies))
            br.addheaders = [('Authorization', 'GoogleLogin auth='+auth)]
        return br
    

    def get_feeds(self):
        feeds = []
        soup = self.index_to_soup('http://www.google.com/reader/api/0/tag/list')
        for id in soup.findAll(True, attrs={'name':['id']}):
            url = id.contents[0]
            feeds.append((re.search('/([^/]*)$', url).group(1),
                          self.base_url + urllib.quote(url.encode('utf-8')) + self.get_options))
        return feeds

    def postprocess_html(self, soup, first):
        #process all the images. assumes that the new html has the correct path
        for tag in soup.findAll(lambda tag: tag.name.lower()=='img' and tag.has_key('src')):
            iurl = tag['src']
            img = Image()
            img.open(iurl)
            width, height = img.size
            print 'img is: ', iurl, 'width is: ', width, 'height is: ', height 
            colorspace='GRAYColorspace'
            img.colorspace='GRAYColorspace'
            if img < 0:
                raise RuntimeError('Out of memory')
            pw = PixelWand()
            if( width > height ) :
                print 'Rotate image'
                colorspace='GRAYColorspace'
                img.rotate(pw, -90)
                img.colorspace='GRAYColorspace'
                img.save(iurl)
        return soup
        #auto_cleanup = True

Last edited by scissors; 11-02-2011 at 03:00 PM.
scissors is offline   Reply With Quote
Old 11-02-2011, 03:01 PM   #13
alansplace
Grand Sorcerer
alansplace ought to be getting tired of karma fortunes by now.alansplace ought to be getting tired of karma fortunes by now.alansplace ought to be getting tired of karma fortunes by now.alansplace ought to be getting tired of karma fortunes by now.alansplace ought to be getting tired of karma fortunes by now.alansplace ought to be getting tired of karma fortunes by now.alansplace ought to be getting tired of karma fortunes by now.alansplace ought to be getting tired of karma fortunes by now.alansplace ought to be getting tired of karma fortunes by now.alansplace ought to be getting tired of karma fortunes by now.alansplace ought to be getting tired of karma fortunes by now.
 
alansplace's Avatar
 
Posts: 5,886
Karma: 464403178
Join Date: Feb 2010
Location: 33.9388° N, 117.2716° W
Device: Kindles K-2, K-KB, PW 1 & 2, Voyage, Fire 2, 5 & HD 8, Surface 3, iPad
Cool try this

Quote:
Originally Posted by madeinlisboa View Post
I'm sorry if this is a dup, but I searched and found nothing.

Is it possible to change images to grayscale when a book is converted? In this case from CHM to MOBI. It would lower substantially the final size.
i'd try this workflow:

1. convert to epub using calibre
2. use calibre's right click option 'tweak epub' to explode the epub
3. use IrfanView (free software at cnet) to batch convert all the graphics files.
4. rebuild the epub using the tweak epub window (it should still be open).
5. convert the epub to mobi with calibre.
alansplace is offline   Reply With Quote
Old 11-02-2011, 03:07 PM   #14
jackie_w
Grand Sorcerer
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 6,208
Karma: 16534692
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
@scissors, I don't claim to know anything about News recipes but I've used the following command in my Calibre plugin to convert an image to greyscale
Code:
img.quantize(number_colors=8, colorspace='GRAYColorspace')
jackie_w is offline   Reply With Quote
Old 11-02-2011, 03:20 PM   #15
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by scissors View Post
Thanks for the replies guys

both
colorspace='GRAYColorspace'
img.colorspace='GRAYColorspace'

compile. I added starson's code to the end of the Sun via google recipe.
Images rotate, but are still colour. :-(
That code won't do it. This will:
Spoiler:
Code:
    def postprocess_html(self, soup, first):
        #process all the images
        for tag in soup.findAll(lambda tag: tag.name.lower()=='img' and tag.has_key('src')):
            iurl = tag['src']
            img = Image()
            img.open(iurl)
            if img < 0:
                raise RuntimeError('Out of memory')
            img.type = "GrayscaleType"
            img.save(iurl)
        return soup

It saved 3KB from a 38KB image
Starson17 is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML + Images = MOBI without Images SunLight Amazon Kindle 5 08-25-2012 02:27 PM
Digitimes: Asustek to launch 8-inch 64-grayscale e-book reader at below US$599 kjk News 12 08-15-2010 01:31 PM
Higher level grayscale, lower contrast? manifestor HanLin eBook 7 05-07-2010 08:32 PM
How much better is eInk from grayscale LCD screens? angelbleu Which one should I buy? 2 11-13-2009 05:19 AM
Cybook is 4 grayscale vs. PRS-505 is 8 grayscale JoeC Bookeen 4 11-06-2007 10:25 AM


All times are GMT -4. The time now is 10:02 PM.


MobileRead.com is a privately owned, operated and funded community.