This will build up to 2 individual images with the title and optional keyword, which will then be added to the real image
497398
def build_text_images(max_width, max_height, stack_title)
      words = [:keyword, :title].keep_if { |a| fetch_text(a) } # optional keyword/title
      results = {}
      trim_boxes = {}
      top_vertical_trim_offset = Float::INFINITY # Init at a large value, as the code will search for a minimal value.
      bottom_vertical_trim_offset = 0
      words.each do |key|
        # Create empty background
        empty_path = File.join(Frameit::ROOT, "lib/assets/empty.png")
        text_image = MiniMagick::Image.open(empty_path)
        image_height = max_height # gets trimmed afterwards anyway, and on the iPad the `y` would get cut
        text_image.combine_options do |i|
          # Oversize as the text might be larger than the actual image. We're trimming afterwards anyway
          i.resize("#{max_width * 5.0}x#{image_height}!") # `!` says it should ignore the ratio
        end

        current_font = font(key)
        text = fetch_text(key)
        UI.verbose("Using #{current_font} as font the #{key} of #{screenshot.path}") if current_font
        UI.verbose("Adding text '#{text}'")

        text.gsub!('\n', "\n")
        text.gsub!(/(?<!\\)(')/) { |s| "\\#{s}" } # escape unescaped apostrophes with a backslash

        interline_spacing = fetch_config['interline_spacing']

        # Add the actual title
        text_image.combine_options do |i|
          i.font(current_font) if current_font
          i.gravity("Center")
          i.pointsize(actual_font_size)
          i.draw("text 0,0 '#{text}'")
          i.interline_spacing(interline_spacing) if interline_spacing
          i.fill(fetch_config[key.to_s]['color'])
        end

        results[key] = text_image

        # Natively trimming the image with .trim will result in the loss of the common baseline between the text in all images when side-by-side (e.g. stack_title is false).
        # Hence retrieve the calculated trim bounding box without actually trimming:
        calculated_trim_box = text_image.identify do |b|
          b.format("%@") # CALCULATED: trim bounding box (without actually trimming), see: http://www.imagemagick.org/script/escape.php
        end

        # Create a Trimbox object from the MiniMagick .identify string with syntax "<width>x<height>+<offset_x>+<offset_y>":
        trim_box = Frameit::Trimbox.new(calculated_trim_box)

        # Get the minimum top offset of the trim box:
        if trim_box.offset_y < top_vertical_trim_offset
          top_vertical_trim_offset = trim_box.offset_y
        end

        # Get the maximum bottom offset of the trim box, this is the top offset + height:
        if (trim_box.offset_y + trim_box.height) > bottom_vertical_trim_offset
          bottom_vertical_trim_offset = trim_box.offset_y + trim_box.height
        end

        # Store for the crop action:
        trim_boxes[key] = trim_box
      end

      # Crop text images:
      words.each do |key|
        # Get matching trim box:
        trim_box = trim_boxes[key]

        # For side-by-side text images (e.g. stack_title is false) adjust the trim box based on top_vertical_trim_offset and bottom_vertical_trim_offset to maintain the text baseline:
        unless stack_title
          # Determine the trim area by maintaining the same vertical top offset based on the smallest value from all trim boxes (top_vertical_trim_offset).
          # When the vertical top offset is larger than the smallest vertical top offset, the trim box needs to be adjusted:
          if trim_box.offset_y > top_vertical_trim_offset
            # Increase the height of the trim box with the difference in vertical top offset:
            trim_box.height += trim_box.offset_y - top_vertical_trim_offset
            # Change the vertical top offset to match that of the others:
            trim_box.offset_y = top_vertical_trim_offset

            UI.verbose("Trim box for key \"#{key}\" is adjusted to align top: #{trim_box}\n")
          end

          # Check if the height needs to be adjusted to reach the bottom offset:
          if (trim_box.offset_y + trim_box.height) < bottom_vertical_trim_offset
            # Set the height of the trim box to the difference between vertical bottom and top offset:
            trim_box.height = bottom_vertical_trim_offset - trim_box.offset_y

            UI.verbose("Trim box for key \"#{key}\" is adjusted to align bottom: #{trim_box}\n")
          end
        end

        # Crop image with (adjusted) trim box parameters in MiniMagick string format:
        results[key].crop(trim_box.string_format)
      end

      results
    end
772561
def build(self, text, size=1):
        
        super(Title, self).build()
        self.content = text
        self.size = size
480973
def _setup_images(directory, brightness, saturation, hue, preserve_transparency):
        
        for file_name in os.listdir(directory):
            with open(os.path.join(directory, file_name), "rb") as fi:
                image = Image.open(fi).convert("RGBA")
            # Only perform required operations
            if brightness != 1.0:
                enhancer = ImageEnhance.Brightness(image)
                image = enhancer.enhance(brightness)
            if saturation != 1.0:
                enhancer = ImageEnhance.Color(image)
                image = enhancer.enhance(saturation)
            if hue != 1.0:
                image = imgops.shift_hue(image, hue)
            if preserve_transparency is True:
                image = imgops.make_transparent(image)
            # Save the new image
            image.save(os.path.join(directory, file_name.replace("gif", "png")))
            image.close()
        for file_name in (item for item in os.listdir(directory) if item.endswith(".gif")):
            os.remove(os.path.join(directory, file_name))
1282605
function handleTag_img() {
    if (!$this->parser->isStartTag) {
      return; # just to be sure this is really an empty tag...
    }

    if (isset($this->parser->tagAttributes['title'])) {
      $this->parser->tagAttributes['title'] = $this->decode($this->parser->tagAttributes['title']);
    } else {
      $this->parser->tagAttributes['title'] = null;
    }
    if (isset($this->parser->tagAttributes['alt'])) {
      $this->parser->tagAttributes['alt'] = $this->decode($this->parser->tagAttributes['alt']);
    } else {
      $this->parser->tagAttributes['alt'] = null;
    }

    if (empty($this->parser->tagAttributes['src'])) {
      # support for "empty" images... dunno if this is really needed
      # but there are some testcases which do that...
      if (!empty($this->parser->tagAttributes['title'])) {
        $this->parser->tagAttributes['title'] = ' '.$this->parser->tagAttributes['title'].' ';
      }
      $this->out('!['.$this->parser->tagAttributes['alt'].']('.$this->parser->tagAttributes['title'].')', true);
      return;
    } else {
      $this->parser->tagAttributes['src'] = $this->decode($this->parser->tagAttributes['src']);
    }

    # [This link][id]
    $link_id = false;
    if (!empty($this->stack['a'])) {
      foreach ($this->stack['a'] as $tag) {
        if ($tag['href'] == $this->parser->tagAttributes['src']
            && $tag['title'] === $this->parser->tagAttributes['title']) {
          $link_id = $tag['linkID'];
          break;
        }
      }
    } else {
      $this->stack['a'] = array();
    }
    if (!$link_id) {
      $link_id = count($this->stack['a']) + 1;
      $tag = array(
        'href' => $this->parser->tagAttributes['src'],
        'linkID' => $link_id,
        'title' => $this->parser->tagAttributes['title']
      );
      array_push($this->stack['a'], $tag);
    }

    $this->out('!['.$this->parser->tagAttributes['alt'].']['.$link_id.']', true);
  }
720425
function(){
		$('.entry-content').each(function(i){
			var _i = i;
			$(this).find('img').each(function(){
				var alt = this.alt;

				if (alt != ''){
					$(this).after('<span class="caption">'+alt+'</span>');
				}

				$(this).wrap('<a href="'+this.src+'" title="'+alt+'" class="fancybox" rel="gallery'+_i+'" />');
			});
		});
	}
362644
def add_image(self, batch_id, image_id, image_properties=None):
    """"""
    if batch_id not in self._data:
      raise KeyError('Batch with ID "{0}" does not exist'.format(batch_id))
    if image_properties is None:
      image_properties = {}
    if not isinstance(image_properties, dict):
      raise ValueError('image_properties has to be dict, however it was: '
                       + str(type(image_properties)))
    self._data[batch_id]['images'][image_id] = image_properties.copy()
935295
def image(self, raw_url, title='', alt=''):
        '''  '''
        max_images = self._config.get('count')
        if max_images is not None and len(self._out.images) >= max_images:
            # We already have enough images, so bail out
            return ' '

        image_specs = raw_url
        if title:
            image_specs += ' "{}"'.format(title)

        alt, container_args = image.parse_alt_text(alt)

        spec_list, _ = image.get_spec_list(image_specs, container_args)

        for spec in spec_list:
            if not spec:
                continue

            self._out.images.append(self._render_image(spec, alt))
            if max_images is not None and len(self._out.images) >= max_images:
                break

        return ' '
338741
def _init_img_params(param):
        

        if param is not None:
            param = np.atleast_1d(param)
            if len(param) == 1:
                param = np.repeat(param, 2)

        return param
765555
function (size, background, foreground, format, text) {
    // Random.image( size, background, foreground, text )
    if (arguments.length === 4) {
      text = format
      format = undefined
    }
    // Random.image( size, background, text )
    if (arguments.length === 3) {
      text = foreground
      foreground = undefined
    }
    // Random.image()
    if (!size) size = this.pick(this._adSize)

    if (background && ~background.indexOf('#')) background = background.slice(1)
    if (foreground && ~foreground.indexOf('#')) foreground = foreground.slice(1)

    // http://dummyimage.com/600x400/cc00cc/470047.png&text=hello
    return 'http://dummyimage.com/' + size +
            (background ? '/' + background : '') +
            (foreground ? '/' + foreground : '') +
            (format ? '.' + format : '') +
            (text ? '&text=' + text : '')
  }
942833
def merge(self, img):
        
        raise NotImplementedError("This method has not be implemented for "
                                  "xarray support.")
        if self.is_empty():
            raise ValueError("Cannot merge an empty image.")

        if self.mode != img.mode:
            raise ValueError("Cannot merge image of different modes.")

        selfmask = self.channels[0].mask
        for chn in self.channels[1:]:
            selfmask = np.ma.mask_or(selfmask, chn.mask)

        for i in range(len(self.channels)):
            self.channels[i] = np.ma.where(selfmask,
                                           img.channels[i],
                                           self.channels[i])
            self.channels[i].mask = np.logical_and(selfmask,
                                                   img.channels[i].mask)
238058
def two_param_shortcut(parser, token):
    
    bits = smart_split(token.contents)
    tagname = bits.next()
    try:
        imageurl = bits.next()
        param1 = bits.next()
        param2 = bits.next()
        param2 = param2.lstrip("#")
    except StopIteration:
        raise template.TemplateSyntaxError("%r tag requires at least the image url" % tagname)

    return MogrifyNode(imageurl, [(tagname, param1, param2), ])
84668
def change(self, inpt, hashfun=DEFAULT_HASHFUN):
        """"""
        self.img = self.__create_image(inpt, hashfun)
242187
def addImg(self, img):
        '''
        
        '''
        # self.opts['imgs'].append(img)

        self.img = imread(img, 'gray', 'uint8')

        didFindCorners, corners = self.method()
        self.opts['foundPattern'].append(didFindCorners)

        if didFindCorners:
            self.findCount += 1
            self.objpoints.append(self.objp)
            self.opts['imgPoints'].append(corners)
        return didFindCorners
700064
def from_image(cls, image, partname):
        
        return ImagePart(partname, image.content_type, image.blob, image)
1102494
def build_item(
    title, key=None, synonyms=None, description=None, img_url=None, alt_text=None
):
    """"""
    item = {
        "info": {"key": key or title, "synonyms": synonyms or []},
        "title": title,
        "description": description,
        "image": {
            "imageUri": img_url or "",
            "accessibilityText": alt_text or "{} img".format(title),
        },
    }
    return item
594459
def add_text(orig, dc, img, text=None):
    
    LOG.info("Add text to image.")

    dc.add_text(**text)

    arr = da.from_array(np.array(img) / 255.0, chunks=CHUNK_SIZE)

    new_data = xr.DataArray(arr, dims=['y', 'x', 'bands'],
                            coords={'y': orig.data.coords['y'],
                                    'x': orig.data.coords['x'],
                                    'bands': list(img.mode)},
                            attrs=orig.data.attrs)
    return XRImage(new_data)
904150
public function add($other, array $options = []): Image
    {
        if (self::isImageish($other)) {
            return self::call('add', $this, [$other], $options);
        } else {
            return $this->linear(1, $other, $options);
        }
    }