calculate required size of capatcha image
435677
private function calculateDimensions()
	{
		# calculate capatcha text box dimensions
		# which are the minimum image resource dimensions
	
		$this->_calculated_text_box['dimensions'] = $this->getTextBoxDimensions(
														$this->_background_text['size'],
														0,
														$this->_background_text['font'],
														$this->_code
														);

		# calculate how much each character takes from width
		$this->_calculated_text_box['char_width'] = $this->_calculated_text_box['dimensions']['width'] / $this->_code_length;

		# calculate additional width to add to the minimum text box width later
		$this->_calculated_text_box['additional_width'] = $this->_calculated_text_box['char_width'] * $this->_code_length + $this->_blocks_seperation;

		$this->_calculated_text_box['additional_height'] = rand( 5, 15 );	
		
		# set Initial Image Information width, height
		
		$this->_image_info['width']  = $this->_calculated_text_box['dimensions']['width']  + $this->_calculated_text_box['additional_width'];
			
		$this->_image_info['height'] = $this->_calculated_text_box['dimensions']['height'] + $this->_calculated_text_box['additional_height'];
		
		
		# Method End
	}
16043
def _normalize_params(image, width, height, crop):
    
    if width is None and height is None:
        raise ValueError("Either width or height must be set. Otherwise "
                         "resizing is useless.")

    if width is None or height is None:
        aspect = float(image.width) / float(image.height)

        if crop:
            raise ValueError("Cropping the image would be useless since only "
                             "one dimention is give to resize along.")

        if width is None:
            width = int(round(height * aspect))
        else:
            height = int(round(width / aspect))

    return (width, height, crop)
134156
def calculate_size(name, expected, updated):
    
    data_size = 0
    data_size += calculate_size_str(name)
    data_size += LONG_SIZE_IN_BYTES
    data_size += LONG_SIZE_IN_BYTES
    return data_size
336206
def parse_size(image, size):
        
        bits = size.split("x")
        if image.size[0] == 0 or image.size[1] == 0:
            ratio = 1.0
        else:
            ratio = float(image.size[0]) / float(image.size[1])

        if len(bits) == 1 or not bits[1]:
            width = int(bits[0])
            height = int(1 / ratio * width)
        elif not bits[0]:
            height = int(bits[1])
            width = int(height * ratio)
        else:
            width, height = map(int, bits)
        return width, height
1095005
def _check_image_size(self, size):
        
        if size % 32 == 0:
            return (0, 0)
        else:
            image_border = 32 - (size % 32)
            if (image_border % 2) == 0:
                return (image_border / 2, image_border / 2)
            else:
                return (image_border / 2, (image_border / 2) + 1)
1221738
function(format, drawable, gc, width, height, dstX, dstY, leftPad, depth, data) {
          var padded = xutil.padded_length(data.length);
          var reqLen = 6 + padded/4; // (length + 3) >> 2 ???
          var padLength = padded - data.length;
          var pad = Buffer.alloc(padLength); // TODO: new pack format 'X' - skip amount of bytes supplied in numerical argument

          // TODO: move code to calculate reqLength and use BigReq if needed outside of corereq.js
          // NOTE: big req is used here (first 'L' in format, 0 and +1 in params), won't work if not enabled
          return [ 'CCSLLLSSssCCxxaa', [72, format, 0, 1+reqLen, drawable, gc, width, height, dstX, dstY, leftPad, depth, data, pad]];
      }
1318123
def getSizeFromPage(rh, page):
    
    rh.printSysLog("Enter generalUtils.getSizeFromPage")

    bSize = float(page) * 4096
    mSize = cvtToMag(rh, bSize)

    rh.printSysLog("Exit generalUtils.getSizeFromPage, magSize: " + mSize)
    return mSize
319520
def size(self):
        """"""
        if self._size and not self._pil_image:
            return self._size
        else:
            return self.pil_image.size
455965
def _get_scaled_image(self, resource):
        
        image = self._get_image()
        original_width, original_height = resource.size

        k = image.size[0] / float(image.size[1])

        if image.size[0] >= image.size[1]:
            target_width = int(original_width * self.size)
            target_height = int(target_width / k)
        else:
            target_height = int(original_height * self.size)
            target_width = int(target_height * k)

        image = image.resize((target_width, target_height), Image.ANTIALIAS)

        return image
974750
def _requiredSize(shape, dtype):
	
	return math.floor(np.prod(np.asarray(shape, dtype=np.uint64)) * np.dtype(dtype).itemsize)
684192
def _get_image_size(self, maxcharno, maxlineno):
        
        return (self._get_char_x(maxcharno) + self.image_pad,
                self._get_line_y(maxlineno + 0) + self.image_pad)
1216536
def get_image_sizes(image):
    """"""

    # It is possible to have the same width appear more than once, if
    # THUMBNAIL_UPSCALE is set to False and the image's width is less than the
    # largest value in FLEXIBLE_IMAGE_SIZES. So keep track of widths and
    # don't output more than one image with the same width (which would result
    # in an invalid `srcset` attribute).
    sizes = []
    seen_widths = []

    for size in settings_sizes():
        img = get_thumbnail_shim(image, size)

        if img.width in seen_widths:
            continue

        seen_widths.append(img.width)

        sizes.append({
            "url": img.url,
            "width": img.width,
            "height": img.height,
        })
    return sizes
217782
def resize_avatar(self, img, base_width):
        
        w_percent = (base_width / float(img.size[0]))
        h_size = int((float(img.size[1]) * float(w_percent)))
        img = img.resize((base_width, h_size), PIL.Image.ANTIALIAS)
        return img
414031
def smart_fit(image, fit_to_width, fit_to_height):
        
        im_width, im_height = image.size
        out_width, out_height = fit_to_width, fit_to_height
        if im_width == 0 or im_height == 0:
            return (fit_to_width, fit_to_height)

        w_scale = float(fit_to_width) / float(im_width)
        h_scale = float(fit_to_height) / float(im_height)
        if w_scale < h_scale:
            scale = float(fit_to_width) / float(im_width)
            out_height = int(round(scale * im_height))
        else:
            scale = float(fit_to_height) / float(im_height)
            out_width = int(round(scale * im_width))

        return out_width, out_height
425847
def resize(self, size):
        """"""
        return Image(self.pil_image.resize(size, PIL.Image.ANTIALIAS))
626006
def scale_min(im, targ, interpolation=cv2.INTER_AREA):
    
    r,c,*_ = im.shape
    ratio = targ/min(r,c)
    sz = (scale_to(c, ratio, targ), scale_to(r, ratio, targ))
    return cv2.resize(im, sz, interpolation=interpolation)
828014
def image_size(self, pnmfile):
        
        pout = os.popen(self.shellsetup + self.pnmfile + ' ' + pnmfile, 'r')
        pnmfileout = pout.read(200)
        pout.close()
        m = re.search(', (\d+) by (\d+) ', pnmfileout)
        if (m is None):
            raise IIIFError(
                text="Bad output from pnmfile when trying to get size.")
        w = int(m.group(1))
        h = int(m.group(2))
        # print "pnmfile output = %s" % (pnmfileout)
        # print "image size = %d,%d" % (w,h)
        return(w, h)