Respond with an image
437656
function sendImg ({ path, res }) {
  res.writeHead(STATUS_OK, {
    'Content-Type': 'image/png'
  })
  fs.createReadStream(path).pipe(res)
}
239913
def render_te_response(self, data):
        """"""
        if 'submit_label' in data and 'url' not in data:
            data['url'] = self.request.get_full_path()

        return JsonResponse(data)
310854
def image(image_format, doc=None):
    """"""
    @on_valid('image/{0}'.format(image_format))
    def image_handler(data, **kwargs):
        if hasattr(data, 'read'):
            return data
        elif hasattr(data, 'save'):
            output = stream()
            if introspect.takes_all_arguments(data.save, 'format') or introspect.takes_kwargs(data.save):
                data.save(output, format=image_format.upper())
            else:
                data.save(output)
            output.seek(0)
            return output
        elif hasattr(data, 'render'):
            return data.render()
        elif os.path.isfile(data):
            return open(data, 'rb')

    image_handler.__doc__ = doc or "{0} formatted image".format(image_format)
    return image_handler
917802
def _updateImage(self):
        """"""
        # Fill the background of the image
        if self.backgroundColor is not None:
            self.textImage.fill(self.backgroundColor)

        # Render the text as a single line, and blit it onto the textImage surface
        if self.mask is None:
            lineSurface = self.font.render(self.text, True, self.textColor)
        else:
            nChars = len(self.text)
            maskedText = self.mask * nChars
            lineSurface = self.font.render(maskedText, True, self.textColor)
        self.textImage.blit(lineSurface, (0, 0))
594702
def set_image(self, img):
        ''''''
        self._bmp = wx.BitmapFromImage(img)
        self.SetMinSize((self._bmp.GetWidth(), self._bmp.GetHeight()))
1159488
def call(file, *args, format: nil)
      img = ::MiniMagick::Image.new(file.path)
      img.quiet
      img.format(format.to_s.downcase, nil) if format
      send(@method, img, *args)
      post_processing(img)

      ::File.open(img.path, "rb")
    end
1338739
def update_image(self, image_id, user_name, desc=None):
        """"""
        desc = desc if desc else ''
        data = {"username": user_name,
                "description": desc}

        return self._post('/images/%s' % image_id, data)
1348927
function(syncOptions, serverResponses) {
    const syncs = [];
    if (syncOptions.pixelEnabled) {
      const brainyResponseObj = serverResponses[0].body;
      if (!brainyResponseObj) {
        return [];
      }
      if (brainyResponseObj.syncUrl && brainyResponseObj.syncUrl != 'null' && brainyResponseObj.syncUrl.length > 0) {
        syncs.push({
          type: 'image',
          url: brainyResponseObj.syncUrl
        });
      }
    }
    return syncs;
  }
802336
function(response) {
            if (!svgCache[url]) {
              svgCache[url] = angular.element('<div>').append(response)[0].querySelector('svg');
            }
            resolve(svgCache[url]);
          }
239435
function(req, res, router) {
    res.send = function() {
      router.sendFn.apply(res, arguments);
    };
    res.sendImage = function() {
      router.sendImageFn.apply(res, arguments);
    };
    res.render = function(file, context){
      if (typeof router.engine === 'string') {
        var engine = require(router.engine)

        router.fs.readFile(router.view + '/' + file + '.' + router.engine, function (err, data) {
          var _html = engine.render(data.toString(), context)
          res.send(_html)
        })
      } else {
        var engine = require(router.engine.eng)

        router.fs.readFile(router.view + '/' + file + '.' + router.engine.ext, function (err, data) {
          var _html = engine.render(data.toString(), context)
          res.send(_html)
        })
      }
    };
  }
1292031
def render_image(**kwargs):
    
    html = ''

    url = kwargs.get('url', None)
    if url:
        html = '<img'

        alt_text = kwargs.get('alt_text', None)
        if alt_text:
            html += ' alt="{}"'.format(alt_text)

        title = kwargs.get('title', None)
        if title:
            html += ' title="{}"'.format(title)

        html += ' src="{}">'.format(url)

    return html
1151713
public function sendResponse()
    {
        // Get rid of BOM markers
        if (ob_get_level()) {
            while (@ob_end_clean() && ob_get_level());
        }
        header("Content-Encoding: none");

        $this->checkConnector();
        $this->checkRequest();

        $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");

        $_thumbnails = $_config->getThumbnailsConfig();
        if (!$_thumbnails->getIsEnabled()) {
            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_THUMBNAILS_DISABLED);
        }

        if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_VIEW)) {
            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
        }

        if (!isset($_GET["FileName"])) {
            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
        }

        $fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["FileName"]);
        $_resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();

        if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName)) {
            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
        }

        $sourceFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName);

        if ($_resourceTypeInfo->checkIsHiddenFile($fileName) || !file_exists($sourceFilePath)) {
            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND);
        }

        $thumbFilePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getThumbsServerPath(), $fileName);

        // If the thumbnail file doesn't exists, create it now.
        if (!file_exists($thumbFilePath)) {
            if(!$this->createThumb($sourceFilePath, $thumbFilePath, $_thumbnails->getMaxWidth(), $_thumbnails->getMaxHeight(), $_thumbnails->getQuality(), true, $_thumbnails->getBmpSupported())) {
                $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
            }
        }

        $size = filesize($thumbFilePath);
        $sourceImageAttr = getimagesize($thumbFilePath);
        $mime = $sourceImageAttr["mime"];

        $rtime = isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])?@strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]):0;
        $mtime =  filemtime($thumbFilePath);
        $etag = dechex($mtime) . "-" . dechex($size);

        $is304 = false;

        if (isset($_SERVER["HTTP_IF_NONE_MATCH"]) && $_SERVER["HTTP_IF_NONE_MATCH"] === $etag) {
            $is304 = true;
        }
        else if($rtime == $mtime) {
            $is304 = true;
        }

        if ($is304) {
            header("HTTP/1.0 304 Not Modified");
            exit();
        }

        //header("Cache-Control: cache, must-revalidate");
        //header("Pragma: public");
        //header("Expires: 0");
        header('Cache-control: public');
        header('Etag: ' . $etag);
        header("Content-type: " . $mime . "; name=\"" . CKFinder_Connector_Utils_Misc::mbBasename($thumbFilePath) . "\"");
        header("Last-Modified: ".gmdate('D, d M Y H:i:s', $mtime) . " GMT");
        //header("Content-type: application/octet-stream; name=\"{$file}\"");
        //header("Content-Disposition: attachment; filename=\"{$file}\"");
        header("Content-Length: ".$size);
        readfile($thumbFilePath);
        exit;
    }
656827
def send_photo(self, *args, **kwargs):
        """"""
        return send_photo(*args, **self._merge_overrides(**kwargs)).run()
89095
def _ProcessImage(self, tag, wall_time, step, image):
    """"""
    event = ImageEvent(wall_time=wall_time,
                       step=step,
                       encoded_image_string=image.encoded_image_string,
                       width=image.width,
                       height=image.height)
    self.images.AddItem(tag, event)
311837
def show_image(self, image_id_or_slug):
        
        if not image_id_or_slug:
            msg = 'image_id_or_slug is required to destroy an image!'
            raise DOPException(msg)

        json = self.request('/images/%s' % image_id_or_slug, method='GET')
        image_json = json.get('image')
        status = json.get('status')
        if status == 'OK':
            image = Image.from_json(image_json)
            return image
        else:
            message = json.get('message')
            raise DOPException('[%s]: %s' % (status, message))
267329
def format_image(self, image, image_format, **kwargs):
        """"""

        image_format = image_format.lower()
        accept = self.request.META['HTTP_ACCEPT'].split(',')

        if FORCE_WEBP and 'image/webp' in accept:
            image_format = 'webp'
        elif image_format == 'png8':
            alpha = image.split()[-1]
            image = image.convert('RGB')
            image = image.convert('P', palette=Image.ADAPTIVE, colors=255)
            image.paste(255, Image.eval(alpha, lambda x: 255 if x <= 128 else 0))
            image_format = 'png'
            kwargs['transparency'] = 255
        elif image_format in ('png32', 'png24'):
            image_format = 'png'

        return super(GetImageView, self).format_image(image, image_format, **kwargs)
162243
function Image() {
  if (!this) return new Image();

  this.url = null;

  EventEmitter.call(this);

  setTimeout(function timeout() {
    if (this.onerror) this.on('error', this.onerror);
    if (this.onload) this.on('load', this.onload);
  }.bind(this));
}