Convert blocks to images.
438936
def toimages(self):
        
        from thunder.images.images import Images

        if self.mode == 'spark':
            values = self.values.values_to_keys((0,)).unchunk()

        if self.mode == 'local':
            values = self.values.unchunk()

        return Images(values)
587278
public function expandBlocks($blocks){

        $decoded = array();
        foreach($blocks as $blockName=>$block){
            $bytes = new GifByteStream($block);
            if(false !== strpos($blockName, 'header')){
                $part = $bytes->bite(3);
                $decoded['signature'] = $this->_hexToAscii($part);
                $part = $bytes->bite(3);
                $decoded['version'] = $this->_hexToAscii($part);
            } else if(false !== strpos($blockName, 'logicalScreenDescriptor')){
                $part = $bytes->bite(2);
                $decoded['canvasWidth'] = hexdec($this->_switchEndian($part));
                $part = $bytes->bite(2);
                $decoded['canvasHeight'] = hexdec($this->_switchEndian($part));
                $part = $bytes->bite(1);
                $bin = $this->_fixSize($this->_hexToBin($part), 8); // Make sure len is correct
                $decoded['globalColorTableFlag'] = bindec(substr($bin, 0 ,1));
                $decoded['colorResolution'] = bindec(substr($bin, 1 ,3));
                $decoded['sortFlag'] = bindec(substr($bin, 4 ,1));
                $decoded['sizeOfGlobalColorTable'] = bindec(substr($bin, 5 ,3));
                $part = $bytes->bite(1);
                $decoded['backgroundColorIndex'] = hexdec($part);
                $part = $bytes->bite(1);
                $decoded['pixelAspectRatio'] = hexdec($part);

            } else if(false !== strpos($blockName, 'globalColorTable')){
                $decoded['globalColorTable'] = $block;
            } else if(false !== strpos($blockName, 'applicationExtension')){
                $index = explode('-', $blockName, 2);
                $index = $index[1];

                $bytes->next(2); // Skip ext intro and label: 21 ff
                $appNameSize = $bytes->bite(1); // 0x0b or 11 according to spec but we check anyways
                $appNameSize = hexdec($appNameSize);
                $appName = $this->_hexToAscii($bytes->bite($appNameSize));
                $subBlocks = array();
                while (!$bytes->isEnd()) { // loop thru all app sub blocks
                    $nextSize = $bytes->bite(1);
                    if($nextSize !== '00'){
                        $size = hexdec($nextSize);
                        $subBlocks[] = $bytes->bite($size);

                    }
                }
                if($appName==='NETSCAPE2.0'){
                    $decoded['applicationExtension'][$index]['appId'] = 'NETSCAPE';
                    $decoded['applicationExtension'][$index]['appCode'] = '2.0';
                    $decoded['applicationExtension'][$index]['subBlocks'] = $subBlocks;
                    $decoded['loopCount'] = hexdec($this->_switchEndian(substr($subBlocks[0], 2, 4)));
                } else {
                    $decoded['applicationExtension'][$index]['appId'] = substr($appName, 0, 8);
                    $decoded['applicationExtension'][$index]['appCode'] = substr($appName, 8, 3);
                    $decoded['applicationExtension'][$index]['subBlocks'] = $subBlocks;
                }
            } else if(false !== strpos($blockName, 'graphicControlExtension')) {
                $index = explode('-', $blockName, 2);
                $index = $index[1];

                $bytes->next(3); // Skip ext intro, label, and block size which is always 4: 21 f9 04
                $part = $bytes->bite(1); // packed field
                $bin = $this->_fixSize($this->_hexToBin($part), 8); // Make sure len is correct
                $decoded['frames'][$index]['disposalMethod'] = bindec(substr($bin, 3 ,3));
                $decoded['frames'][$index]['userInputFlag'] = bindec(substr($bin, 6 ,1));
                $decoded['frames'][$index]['transparentColorFlag'] = bindec(substr($bin, 7 ,1));
                $part = $bytes->bite(2);
                $decoded['frames'][$index]['delayTime'] = hexdec($this->_switchEndian($part));
                $part = $bytes->bite(1);
                $decoded['frames'][$index]['transparentColorIndex'] = hexdec($part);
            } else if(false !== strpos($blockName, 'imageDescriptor')) {
                $index = explode('-', $blockName, 2);
                $index = $index[1];

                $bytes->next(1); // skip separator: 2c
                $part                                               = $bytes->bite(2);
                $decoded['frames'][$index]['imageLeft']             = hexdec($this->_switchEndian($part));
                $part                                               = $bytes->bite(2);
                $decoded['frames'][$index]['imageTop']              = hexdec($this->_switchEndian($part));
                $part                                               = $bytes->bite(2);
                $decoded['frames'][$index]['imageWidth']            = hexdec($this->_switchEndian($part));
                $part                                               = $bytes->bite(2);
                $decoded['frames'][$index]['imageHeight']           = hexdec($this->_switchEndian($part));
                $part                                               = $bytes->bite(1); // packed field
                $bin                                                = $this->_fixSize($this->_hexToBin($part),
                    8);
                $decoded['frames'][$index]['localColorTableFlag']   = bindec(substr($bin, 0, 1));
                $decoded['frames'][$index]['interlaceFlag']         = bindec(substr($bin, 1, 1));
                $decoded['frames'][$index]['sortFlag']              = bindec(substr($bin, 2, 1));
                $decoded['frames'][$index]['sizeOfLocalColorTable'] = bindec(substr($bin, 5, 3));
            } else if(false !== strpos($blockName, 'localColorTable')){
                $index = explode('-', $blockName, 2);
                $index = $index[1];
                $decoded['frames'][$index]['localColorTable'] = $block;
            } else if(false !== strpos($blockName, 'imageData')) {
                $index = explode('-', $blockName, 2);
                $index = $index[1];

                $decoded['frames'][$index]['imageData'] = $block;
            } else if($blockName === 'trailer') {
                $decoded['trailer'] = $block;
            }
            unset($bytes);
        }

        return $decoded;
    }
1051839
def convert_out(self, obj):
        """"""
        newobj = super(ProcessedImageProduct, self).convert_out(obj)
        if newobj:
            hdulist = newobj.open()
            hdr = hdulist[0].header
            if 'EMIRUUID' not in hdr:
                hdr['EMIRUUID'] = str(uuid.uuid1())
        return newobj
1136297
def _writeblocks(cls, blocks, available, cont_size, padding_func):
        """"""

        # write everything except padding
        data = bytearray()
        for block in blocks:
            if isinstance(block, Padding):
                continue
            data += cls._writeblock(block)
        blockssize = len(data)

        # take the padding overhead into account. we always add one
        # to make things simple.
        padding_block = Padding()
        blockssize += len(cls._writeblock(padding_block))

        # finally add a padding block
        info = PaddingInfo(available - blockssize, cont_size)
        padding_block.length = min(info._get_padding(padding_func),
                                   cls._MAX_SIZE)
        data += cls._writeblock(padding_block, is_last=True)

        return data
537539
def block_to_svg(block=None):
    
    block = working_block(block)
    try:
        from graphviz import Source
        return Source(block_to_graphviz_string())._repr_svg_()
    except ImportError:
        raise PyrtlError('need graphviz installed (try "pip install graphviz")')
455869
def gen_image(img, width, height, outfile, img_type='grey'):
    """"""
    assert len(img) == width * height or len(img) == width * height * 3

    if img_type == 'grey':
        misc.imsave(outfile, img.reshape(width, height))

    elif img_type == 'color':
        misc.imsave(outfile, img.reshape(3, width, height))
705631
private static Block convertBlock(TBlock tblk) {
    return new Block(tblk.getBlockId(), 
                     tblk.getNumBytes(),
                     tblk.getGenerationStamp());
  }
860658
def processing_blocks(self):
        """"""
        pb_list = ProcessingBlockList()
        # TODO(BMo) realtime, offline etc.
        return json.dumps(dict(active=pb_list.active,
                               completed=pb_list.completed,
                               aborted=pb_list.aborted))
1348450
def convert(format)
      ptr = ZBar.zbar_image_convert(@img, format)
      if ptr.null?
        raise ArgumentError, "conversion failed"
      else
        Image.new(ptr)
      end
    end
111450
def latents_to_frames(z_top_interp, level_eps_interp, hparams):
  """"""
  # Decode [z^1_t, z^2_t .. z^l_t] to [X_t]
  images, _, _, _ = glow_ops.encoder_decoder(
      "codec", z_top_interp, hparams, eps=level_eps_interp, reverse=True)
  images = glow_ops.postprocess(images)
  return images
797616
def _gather_image_parts(self):
        """"""
        for rel in self.iter_rels():
            if rel.is_external:
                continue
            if rel.reltype != RT.IMAGE:
                continue
            if rel.target_part in self.image_parts:
                continue
            self.image_parts.append(rel.target_part)
1007271
def _convert(self, image, output=None):
        """"""
        with Image.open(image) as im:
            width, height = im.size

            co = CanvasObjects()
            co.add(CanvasImg(image, 1.0, w=width, h=height))

            return WatermarkDraw(co, tempdir=self.tempdir, pagesize=(width, height)).write(output)
547092
def _renderBlockDevice(self, block_device, build):
        """"""
        rendered_block_device = yield build.render(block_device)
        if rendered_block_device['volume_size'] is None:
            source_type = rendered_block_device['source_type']
            source_uuid = rendered_block_device['uuid']
            volume_size = self._determineVolumeSize(source_type, source_uuid)
            rendered_block_device['volume_size'] = volume_size
        return rendered_block_device
416378
def render_blocks(self, template_name, **context):
        
        blocks = {}
        template = self._get_template(template_name)
        for block in template.blocks:
            blocks[block] = self._render_context(template,
                                                template.blocks[block],
                                                **context)
        return blocks
661978
def run(self, lines):
        """"""
        ret = []

        for block in self.blocks(lines):
            ret.extend(self.convert_table(block))

        return ret
560419
def convert(self, blob, size=500):
        """"""
        file_list = []
        with make_temp_file(blob) as in_fn, make_temp_file() as out_fn:
            try:
                subprocess.check_call(["pdftoppm", "-jpeg", in_fn, out_fn])
                file_list = sorted(glob.glob(f"{out_fn}-*.jpg"))

                converted_images = []
                for fn in file_list:
                    converted = resize(open(fn, "rb").read(), size, size)
                    converted_images.append(converted)

                return converted_images
            except Exception as e:
                raise ConversionError("pdftoppm failed") from e
            finally:
                for fn in file_list:
                    try:
                        os.remove(fn)
                    except OSError:
                        pass
970245
def build_pic_map(self):
        """"""
        if self.pic_to_replace:
            # Main document
            part=self.docx.part
            self.pic_map.update(self._img_filename_to_part(part))

            # Header/Footer
            for relid, rel in six.iteritems(self.docx.part.rels):
                if rel.reltype in (REL_TYPE.HEADER,REL_TYPE.FOOTER):
                    self.pic_map.update(self._img_filename_to_part(rel.target_part))