                                "-dLastPage=#{opts.last_page}",
                                "-dDownScaleFactor=#{opts.downscale}",
                                @filename_pdf]
+                else if @image_type == "jpg"
+                    args = ['-dBATCH', '-dNOPAUSE',
+                                '-sDEVICE=jpeg',
+                               "-sOutputFile=#{tmp}/%d.jpg",
+                               "-r#{opts.resolution}",
+                               "-dFirstPage=#{opts.first_page}",
+                               "-dLastPage=#{opts.last_page}",
+                               "-dJPEGQ=#{opts.jpeg_quality}",
+                               @filename_pdf] 
+                else
+                    cb("unknown image type #{@image_type}")
+                    return
                 console.log(args)
                 @_exec
                     command : 'gs'

                        @_updating = false
                        opts.cb?(err)
                        return
                        ###
                        for pg in @output.children()
                            page = $(pg)
                            m = page.data('number')
                            if m < first_page or m > last_page
                                #  free mem used by pages not visible, to save RAM.
                                console.log('freeing ', m)                                
                                img = page.find('img')
                                src = img.attr('src')
                                if src
                                    img.remove()
                                    dumped = $("<img alt='Page #{m}' class='salvus-editor-pdf-preview-image img-rounded'>")
                                    dumped.data('dumped', src)
                                    page.append(dumped)
                            else if m not in changed_pages
                                # refetch page from server
                                # src =                                 
                        ###
                        
                        
    # update page n based on currently computed data.
    _update_page: (n, cb) =>    
        p = @pdflatex.page(n)
        url = p.png_url
        console.log('update: ', n, url)
        if not url?
            # todo: delete page and all following it from DOM

        # for now... for debugging.
        @_text = text

    # Updates previews for a given range of pages.
    # This computes images on backend, and fills in the sha1 hashes of @pages.
    # If any sha1 hash changes from what was already there, it gets temporary
    # url for that file.
    # It assumes the pdf files is there already, and doesn't run pdflatex.
    update_images: (opts={}) =>
        opts = defaults opts,
            first_page : 1
            last_page  : undefined  # defaults to @num_pages, unless 0 in which case 99999
            cb         : undefined  # cb(err, [array of page numbers of pages that changed])
            resolution : '50'      # 'number' or 'number1xnumber2'
            device     : '16m'      # one of '16', '16m', '256', '48', 'alpha', 'gray', 'mono'  (ignored if image_type='jpg')
            png_downscale  : 2      # ignored if image type is jpg
            jpeg_quality   : 75     # jpg only -- scale of 1 to 100  

        if not opts.last_page?
            opts.last_page = @num_pages
