Retrieve a image from an incoming message.
@return array A download for the image file.
@throws TelegramAttachmentException
346950
private function getImages()
    {
        $photos = $this->event->get('photo');
        $largetstPhoto = array_pop($photos);
        $response = $this->http->get($this->buildApiUrl('getFile'), [
            'file_id' => $largetstPhoto['file_id'],
        ]);

        $responseData = json_decode($response->getContent());

        if ($response->getStatusCode() !== 200) {
            throw new TelegramAttachmentException('Error retrieving file url: '.$responseData->description);
        }

        $url = $this->buildFileApiUrl($responseData->result->file_path);

        return [new Image($url, $largetstPhoto)];
    }
1364892
protected function get_meta_data() {
        //gather meta data
        if (empty($this->imagestring)) {
            $info = getimagesize($this->filename);
            switch ($info['mime']) {
                case 'image/gif':
                    $this->image = imagecreatefromgif($this->filename);
                    break;
                case 'image/jpeg':
                    $this->image = imagecreatefromjpeg($this->filename);
                    break;
                case 'image/png':
                    $this->image = imagecreatefrompng($this->filename);
                    break;
                default:
                    throw new Exception('Invalid image: ' . $this->filename);
                    break;
            }
        } elseif (function_exists('getimagesizefromstring')) {
            $info = getimagesizefromstring($this->imagestring);
        } else {
            throw new Exception('PHP 5.4 is required to use method getimagesizefromstring');
        }
        $this->original_info = array(
            'width' => $info[0],
            'height' => $info[1],
            'orientation' => $this->get_orientation(),
            'exif' => function_exists('exif_read_data') && $info['mime'] === 'image/jpeg' && $this->imagestring === null ? $this->exif = @exif_read_data($this->filename) : null,
            'format' => preg_replace('/^image\//', '', $info['mime']),
            'mime' => $info['mime']
        );
        $this->width = $info[0];
        $this->height = $info[1];
        imagesavealpha($this->image, true);
        imagealphablending($this->image, true);
        return $this;
    }
1239573
public function formatIncomingRequest($telegram)
    {
        if ( ! empty($telegram) && is_array($telegram)) {
            $sender_id = null;
            $time = null;

            if (isset($telegram['callback_query'])) {
                $message    = $telegram['callback_query'];
                $sender_id  = $telegram['callback_query']['from']['id'];
                $time       = $telegram['callback_query']['message']['date'];
            } else if (isset($telegram['message'])) {
                $sender_id = $telegram['message']['from']['id'];
                $time = $telegram['message']['date'];
            } else {
                return $telegram;
            }

            $facebook = [
                'object' => 'page',
                'entry' => [
                    [
                        'id' => rand(),
                        'time' => $time,
                        'messaging' => [
                            [
                                'sender' => [
                                    'id' => $sender_id,
                                ],
                                'recipient' => [
                                    'id' => rand()
                                ],
                                'timestamp' => $time,
                            ]
                        ]
                    ]
                ]
            ];

            if ( ! empty($telegram['message']['text'])) {
                $facebook['entry'][0]['messaging'][0]['message'] = [
                    'text' => $telegram['message']['text']
                ];
            }

            if ( ! empty($telegram['callback_query']['data'])) {
                $facebook['entry'][0]['messaging'][0]['postback'] = [
                    'payload' => $telegram['callback_query']['data']
                ];
            }

            return $facebook;
        }

        return $telegram;
    }
1060469
protected function getAttachmentPayload($text = null, $title = null, $images = null, $color = null)
    {
        $attachment = [];

        if ($text) {
            $attachment['text'] = $this->stringValue($text);
        }

        if ($title) {
            $attachment['title'] = $this->stringValue($title);
        }

        if ($images = $this->getImagesPayload($images)) {
            $attachment['images'] = $images;
        }

        if ($color) {
            $attachment['color'] = (string) $color;
        }

        return $attachment;
    }
910515
public static function Telegram($text, $attachment = '', $inline_keyboard = '')
    {
        if (Config::get('larasap.telegram.channel_signature')) {
            $type = isset($attachment['type']) ? 'caption' : 'text';
            $text = self::assignSignature($text, $type);
        }

        if ($attachment) {
            switch ($attachment['type']) {
                case 'photo':
                    $result = TelegramApi::sendPhoto(null, $attachment['file'], $text, $inline_keyboard);
                    break;
                case 'audio':
                    $duration = isset($attachment['duration']) ? $attachment['duration'] : '';
                    $performer = isset($attachment['performer']) ? $attachment['performer'] : '';
                    $title = isset($attachment['title']) ? $attachment['title'] : '';
                    $result = TelegramApi::sendAudio(null, $attachment['file'], $text, $duration, $performer, $title, $inline_keyboard);
                    break;
                case 'document':
                    $result = TelegramApi::sendDocument(null, $attachment['file'], $text, $inline_keyboard);
                    break;
                case 'video':
                    $duration = isset($attachment['duration']) ? $attachment['duration'] : '';
                    $width = isset($attachment['width']) ? $attachment['width'] : '';
                    $height = isset($attachment['height']) ? $attachment['height'] : '';
                    $result = TelegramApi::sendVideo(null, $attachment['file'], $duration, $width, $height, $text, $inline_keyboard);
                    break;
                case 'voice':
                    $duration = isset($attachment['duration']) ? $attachment['duration'] : '';
                    $result = TelegramApi::sendVoice(null, $attachment['file'], $text, $duration, $inline_keyboard);
                    break;
                case 'media_group':
                    $result = TelegramApi::sendMediaGroup(null, json_encode($attachment['files']));
                    break;
                case 'location':
                    $live_period = isset($attachment['live_period']) ? $attachment['live_period'] : '';
                    $result = TelegramApi::sendLocation(null, $attachment['latitude'], $attachment['longitude'], $live_period, $inline_keyboard);
                    break;
                case 'venue':
                    $foursquare_id = isset($attachment['foursquare_id']) ? $attachment['foursquare_id'] : '';
                    $result = TelegramApi::sendVenue(null, $attachment['latitude'], $attachment['longitude'], $attachment['title'], $attachment['address'], $foursquare_id, $inline_keyboard);
                    break;
                case 'contact':
                    $last_name = isset($attachment['last_name']) ? $attachment['last_name'] : '';
                    $result = TelegramApi::sendContact(null, $attachment['phone_number'], $attachment['first_name'], $last_name, $inline_keyboard);
                    break;
            }
        } else {
            $result = TelegramApi::sendMessage(null, $text, $inline_keyboard);
        }

        return $result;
    }
1270045
public function getImage()
    {
        $value = parent::getValue();
        
        if ($value) {
            return Yii::$app->storage->getImage($value);
        }
        
        return false;
    }
532654
public function getImageBlob()
    {
        if (!$this->processed) {
            return file_get_contents($this->source);
        }

        if ($this->isMultipartImage()) {

            $this->tmpFile = tempnam($this->tmp, 'jitim_');

            $image = $this->resource->deconstructImages();
            $image->writeImages($this->tmpFile, true);

            $image->clear();
            $image->destroy();

            return file_get_contents($this->tmpFile);

        }

        return $this->resource->getImageBlob();
    }
1205855
private function getResource()
    {
        if ($this->mime == 'image/gif') {
            return imagecreatefromgif($this->source);
        }
        elseif ($this->mime == 'image/jpg' || $this->mime == 'image/jpeg') {
            return imagecreatefromjpeg($this->source);
        }
        elseif ($this->mime == 'image/png') {
            return imagecreatefrompng($this->source);
        }
        else
            return null;

    }
586033
protected function genericMessageToArray()
    {
        $message = [];
        $message['recipient'] = $this->recipient;
        $message['notification_type'] = $this->notificationType;
        $message['message']['attachment']['type'] = 'template';
        $message['message']['attachment']['payload']['template_type'] = 'generic';
        $message['message']['attachment']['payload']['elements'] = $this->cards;

        return $message;
    }
42960
public function getImage()
    {
        $this->imageWidth = null;
        $this->imageHeight = null;

        $images = $this->images;
        $bigger = (bool) $this->getConfig('choose_bigger_image');
        $minWidth = $this->getConfig('min_image_width', 1);
        $minHeight = $this->getConfig('min_image_height', 1);

        $images = array_filter($images, function ($image) use ($minWidth, $minHeight) {
            return $image['width'] >= $minWidth && $image['height'] >= $minHeight;
        });

        if (empty($images)) {
            return null;
        }

        reset($images);
        $image = current($images);

        if ($bigger) {
            $sizes = [];

            foreach ($images as $img) {
                $sizes[$img['url']] = $img['size'];
            }

            $biggest = static::getBigger($sizes);

            foreach ($images as $img) {
                if ($biggest == $img['url']) {
                    $image = $img;
                    break;
                }
            }
        }

        $this->imageWidth = $image['width'];
        $this->imageHeight = $image['height'];

        return $image['url'];
    }
225042
public function getImage()
    {
        // No fields, no image.
        if (empty($this->contenttype['fields'])) {
            return '';
        }

        // Grab the first field of type 'image', and return that.
        foreach ($this->contenttype['fields'] as $key => $field) {
            if ($field['type'] === 'image' && isset($this->values[$key])) {
                // After v1.5.1 we store image data as an array
                if (is_array($this->values[$key])) {
                    return isset($this->values[$key]['file']) ? $this->values[$key]['file'] : '';
                }

                return $this->values[$key];
            }
        }

        // otherwise, no image.
        return '';
    }
341599
public function downloadFile($telegram_file_path, $local_file_path)
    {
        $file_url = 'https://api.telegram.org/file/bot'.$this->bot_token.'/'.$telegram_file_path;
        $in = fopen($file_url, 'rb');
        $out = fopen($local_file_path, 'wb');

        while ($chunk = fread($in, 8192)) {
            fwrite($out, $chunk, 8192);
        }
        fclose($in);
        fclose($out);
    }
1247062
protected function getImages()
    {
        $table = ORM::getTable($this->getTable()->getPlugin(), 'Image');
        $q = $table->createSelectQuery();
        $q->where(
            $q->expr->lAnd(
                $q->expr->eq('groupId', $q->bindValue($this->id, null, PDO::PARAM_INT)),
                $q->expr->eq('active', $q->bindValue(true, null, PDO::PARAM_BOOL))
            )
        );
        $q->orderBy('position');
        return $table->loadFromQuery($q);
    }
157217
public function image()
	{
		if (substr($this->file->body, 0, 6) === 'GIF87a'
			|| substr($this->file->body, 0, 6) === 'GIF89a')
		{
			return 'image/gif';
		}
		elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
		{
			return 'image/png';
		}
		elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
		{
			return 'image/jpeg';
		}
		elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
		{
			return 'image/bmp';
		}
		elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00")
		{
			return 'image/vnd.microsoft.icon';
		}
		else
		{
			return false;
		}
	}
455174
protected function getAttachmentsArray($message)
    {
        $attachments = array();

        foreach ($message->getChildren() as $entity) {
            if ($entity instanceof Swift_Attachment) {
                $attachments[] = array(
                    'name' => $entity->getFilename(),
                    'data' => $entity->getBody(),
                    'content_id' => "<{$entity->getContentType()}>"
                );
            }
        }

        return $attachments;
    }
1359751
public function getMessages()
    {
        return $this->event->map(function ($message) {
            if (isset($message['picUrl'])) {
                $image = new Image($message['picUrl'], $message);
                $image->title($message['attribution']['name']);

                $incomingMessage = new IncomingMessage(Image::PATTERN, $message['from'], $message['chatId'], $message);
                $incomingMessage->setImages([$image]);
            } elseif (isset($message['stickerUrl'])) {
                $sticker = new Image($message['stickerUrl'], $message);
                $sticker->title($message['attribution']['name']);

                $incomingMessage = new IncomingMessage(Image::PATTERN, $message['from'], $message['chatId'], $message);
                $incomingMessage->setImages([$sticker]);
            } elseif (isset($message['videoUrl'])) {
                $incomingMessage = new IncomingMessage(Video::PATTERN, $message['from'], $message['chatId'], $message);
                $incomingMessage->setVideos([new Video($message['videoUrl'], $message)]);
            } else {
                $incomingMessage = new IncomingMessage($message['body'], $message['from'], $message['chatId'], $message);
            }

            return $incomingMessage;
        })->toArray();
    }
90671
public function getHTMLBodyWithEmbeddedBase64Images() {
        return $this->getCustomHTMLBody(function($body, $oAttachment){
            /** @var \Webklex\IMAP\Attachment $oAttachment */
            if ($oAttachment->id && $oAttachment->getImgSrc() != null) {
                $body = str_replace('cid:'.$oAttachment->id, $oAttachment->getImgSrc(), $body);
            }

            return $body;
        });
    }