generate image by hash, usese tempfile :-/
508871
def hashimage(hashvalue):
    """"""
    tmpf = tempfile.mkstemp(".png")[1]
    image = pagan.Avatar("")
    image.img = pagan.generator.generate_by_hash(hashvalue)
    image.save("/", tmpf)
    return static_file(tmpf, root="/")
969830
def get_temp_filename(self, hash_key=None):
        '''
        
        '''

        if not hash_key:
            hash_key = six.text_type(uuid4())

        temp_filename = '{0}/{1}'.format(
            self.config.TEMP_DIR, sha1_hash(hash_key),
        )

        return temp_filename
1372700
def to_hash
      h = {:width => width, :height => height, :bits => bits, :comment => comment}
      h.merge!(exif) if exif?
      h
    end
1093109
function createFilenameHash(uploadDir, files) {
    let hashPath = path.resolve(uploadDir, 'name.json');
    let hashContent;
    let result = [];

    if (hashFileExist || fs.existsSync(hashPath)) {
      try {
        let content = fs.readFileSync(hashPath, 'utf8');
        hashContent = JSON.parse(content);
      } catch (err) {
        debug('get hash file failed:' + err);
      }
    } else {
      hashContent = {};
    }

    for (let item in files) {
      let fileName = files[item].name;
      let hashName = getUniqueId(0, hashContent, fileName);

      let fileItem = getFileItem(files[item], uploadDir)
      hashContent[hashName] = fileItem;
      result.push(util._extend(fileItem, {
        filename: hashName
      }))
    }

    try {
      let file = JSON.stringify(hashContent, null, 2);
      fs.writeFileSync(hashPath, file);
    } catch (err) {
      debug('write hash file failed:' + err);
    }

    hashFileExist = true;

    return result;
  }
673704
function ImagePngWithAlpha($file, $x, $y, $w=0, $h=0, $link='')
{
    $tmp_alpha = tempnam('.',  'mska');
    $this->tmpFiles[] = $tmp_alpha;
    $tmp_plain = tempnam('.',  'mskp');
    $this->tmpFiles[] = $tmp_plain;
    
    list($wpx,  $hpx) = getimagesize($file);
    $img = imagecreatefrompng($file);
    $alpha_img = imagecreate( $wpx,  $hpx );
    
    // generate gray scale pallete
    for($c=0;$c<256;$c++) ImageColorAllocate($alpha_img,  $c,  $c,  $c);
    
    // extract alpha channel
    $xpx=0;
    while ($xpx<$wpx){
        $ypx = 0;
        while ($ypx<$hpx){
            $color_index = imagecolorat($img,  $xpx,  $ypx);
            $alpha = 255-($color_index>>24)*255/127; // GD alpha component: 7 bit only,  0..127!
            imagesetpixel($alpha_img,  $xpx,  $ypx,  $alpha);
        ++$ypx;
        }
        ++$xpx;
    }

    imagepng($alpha_img,  $tmp_alpha);
    imagedestroy($alpha_img);
    
    // extract image without alpha channel
    $plain_img = imagecreatetruecolor ( $wpx,  $hpx );
    imagecopy ($plain_img,  $img,  0,  0,  0,  0,  $wpx,  $hpx );
    imagepng($plain_img,  $tmp_plain);
    imagedestroy($plain_img);
    
    //first embed mask image (w,  h,  x,  will be ignored)
    $maskImg = $this->Image($tmp_alpha,  0, 0, 0, 0,  'PNG',  '',  true); 
    
    //embed image,  masked with previously embedded mask
    $this->Image($tmp_plain, $x, $y, $w, $h, 'PNG', $link,  false,  $maskImg);
}
79567
def hash_file(file_path, block_size = 65536):
    
    sha = hashlib.sha256()
    with open(file_path, 'rb') as h_file:
        file_buffer = h_file.read(block_size)
        while len(file_buffer) > 0:
            sha.update(file_buffer)
            file_buffer = h_file.read(block_size)
    return sha.hexdigest()
1123208
def hash_file(filename):
    
    hasher = hashlib.sha1()
    with open(filename, 'rb') as f:
        buf = f.read(65536)
        while len(buf) > 0:
            hasher.update(buf)
            buf = f.read(65536)

    return hasher.hexdigest()
1315583
def image(out = nil)
      splash_start
      splash_composite
      return img unless out
      FileUtils.mkdir_p File.dirname(out)
      img.write(out)
    rescue Errno::ENOENT
      YAMG.puts_and_exit("Path not found '#{out}'")
    end
302827
def generate_hash_comment(file_path):
    
    with open(file_path, 'rb') as fp:
        hexdigest = hashlib.sha1(fp.read().strip()).hexdigest()
    return "# SHA1:{0}\n".format(hexdigest)
1158457
def with_temp_file
      filename = original_filename || content.default_file_name
      basename = [ File.basename(filename, ".*"), File.extname(filename) ]
      infile = Tempfile.open(basename, Ddr::Models.tempdir, encoding: 'ascii-8bit')
      begin
        infile.write(content.content)
        infile.close
        verify_checksum!(infile)
        yield infile.path
      ensure
        infile.close unless infile.closed?
        File.unlink(infile)
      end
    end
136171
def _gen_md5_filehash(fname, *args):
    '''
    
    '''
    _hash = hashlib.md5()
    with salt.utils.files.fopen(fname, 'rb') as f:
        for chunk in iter(lambda: f.read(4096), b''):
            _hash.update(chunk)

    for extra_arg in args:
        _hash.update(six.b(str(extra_arg)))
    return _hash.hexdigest()
1185980
def WriteFileHash(self, path, hash_value):
    
    string = '{0:s}\t{1:s}\n'.format(hash_value, path)

    encoded_string = self._EncodeString(string)
    self._file_object.write(encoded_string)
21532
def with_tmpfile
      path = [@file, $$.to_s(36), Thread.current.object_id.to_s(36)].join
      file = File.open(path, 'wb')
      yield(path, file)
    ensure
      file.close unless file.closed?
      File.unlink(path) if File.exists?(path)
    end
881040
def generate(load_path, rescan = false)
      requireables = load_path.reverse_each.flat_map do |path|
        path = path.to_s
        if rescan
          entries[path] = Entry.new(path).requireables
        else
          entries[path] ||= Entry.new(path).requireables
        end
      end
      Hash[requireables]
    end
192945
def transform_hash(hash, path = "")
      hash.each_with_object({}) do |(k, v), ret|
        key = path + k.to_s

        if v.is_a?(Hash)
          ret.merge! transform_hash(v, "#{key}:")
        else
          ret[key] = v
        end
      end
    end
36693
def generate(str, alg):
    """"""
    img = Image.new(IMAGE_MODE, IMAGE_SIZE, BACKGROUND_COLOR)
    hashcode = hash_input(str, alg)
    pixelmap = setup_pixelmap(hashcode)
    draw_image(pixelmap, img)
    return img
13526
def generateThumbnail(self):
        """"""
        image = pilImage.open(ROOT / self.source.name)
        box, width, height = cropBox(self.width, self.height)

        # Resize
        image.thumbnail((width, height), pilImage.ANTIALIAS)
        # Crop from center
        box = cropBox(*image.size)[0]
        image = image.crop(box)
        # save
        self.thumbnail = self.source.name.replace(self.hash, '__{}'.format(self.hash))
        image.save(ROOT / self.thumbnail.name)