use Friendica\Protocol\Activity;
use Friendica\Protocol\Diaspora;
use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Images;
use Friendica\Util\Network;
use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings;
api_user()
);
if (DBA::isResult($r)) {
- $phototypes = Image::supportedTypes();
+ $phototypes = Images::supportedTypes();
$ext = $phototypes[$r[0]['type']];
$description = $r[0]['desc'] ?? '';
$_REQUEST['body'] .= "\n\n" . '[url=' . System::baseUrl() . '/photos/' . $r[0]['nickname'] . '/image/' . $r[0]['resource-id'] . ']';
$attachments = [];
foreach ($images[1] as $image) {
- $imagedata = Image::getInfoFromURL($image);
+ $imagedata = Images::getInfoFromURLCached($image);
if ($imagedata) {
$attachments[] = ["url" => $image, "mimetype" => $imagedata["mime"], "size" => $imagedata["size"]];
$start = iconv_strpos($text, $url, $offset, "UTF-8");
if (!($start === false)) {
- $image = Image::getInfoFromURL($url);
+ $image = Images::getInfoFromURLCached($url);
if ($image) {
// If image cache is activated, then use the following sizes:
// thumb (150), small (340), medium (600) and large (1024)
$media_url = ProxyUtils::proxifyUrl($url);
$sizes = [];
- $scale = Image::getScalingDimensions($image[0], $image[1], 150);
+ $scale = Images::getScalingDimensions($image[0], $image[1], 150);
$sizes["thumb"] = ["w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"];
if (($image[0] > 150) || ($image[1] > 150)) {
- $scale = Image::getScalingDimensions($image[0], $image[1], 340);
+ $scale = Images::getScalingDimensions($image[0], $image[1], 340);
$sizes["small"] = ["w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"];
}
- $scale = Image::getScalingDimensions($image[0], $image[1], 600);
+ $scale = Images::getScalingDimensions($image[0], $image[1], 600);
$sizes["medium"] = ["w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"];
if (($image[0] > 600) || ($image[1] > 600)) {
- $scale = Image::getScalingDimensions($image[0], $image[1], 1024);
+ $scale = Images::getScalingDimensions($image[0], $image[1], 1024);
$sizes["large"] = ["w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"];
}
} else {
}
if ($filetype == "") {
- $filetype=Image::guessType($filename);
+ $filetype = Images::guessType($filename);
}
$imagedata = @getimagesize($src);
if ($imagedata) {
use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\Database\DBA;
-use Friendica\Object\Image;
+use Friendica\Util\Images;
use Friendica\Util\Strings;
/**
function _map_files1($rr)
{
$a = \get_app();
- $types = Image::supportedTypes();
+ $types = Images::supportedTypes();
$ext = $types[$rr['type']];
$filename_e = $rr['filename'];
use Friendica\Util\ACLFormatter;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Images;
use Friendica\Util\Map;
use Friendica\Util\Security;
use Friendica\Util\Strings;
Logger::log('mod_photos: REQUEST ' . print_r($_REQUEST, true), Logger::DATA);
Logger::log('mod_photos: FILES ' . print_r($_FILES, true), Logger::DATA);
- $phototypes = Image::supportedTypes();
+ $phototypes = Images::supportedTypes();
$can_post = false;
$visitor = 0;
}
if ($type == "") {
- $type = Image::guessType($filename);
+ $type = Images::guessType($filename);
}
Logger::log('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', Logger::DEBUG);
return;
}
- $phototypes = Image::supportedTypes();
+ $phototypes = Images::supportedTypes();
$_SESSION['photo_return'] = $a->cmd;
*/
use Friendica\App;
+use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
-use Friendica\Core\System;
use Friendica\Core\Session;
-use Friendica\Core\Config;
+use Friendica\Core\System;
use Friendica\Database\DBA;
-use Friendica\Model\Contact;
use Friendica\Model\Photo;
use Friendica\Model\User;
use Friendica\Object\Image;
+use Friendica\Util\Images;
use Friendica\Util\Strings;
function wall_upload_post(App $a, $desktopmode = true)
}
if ($filetype == "") {
- $filetype = Image::guessType($filename);
+ $filetype = Images::guessType($filename);
}
// If there is a temp name, then do a manual check
use Friendica\Network\Probe;
use Friendica\Object\Image;
use Friendica\Protocol\Activity;
+use Friendica\Util\Images;
use Friendica\Util\Map;
use Friendica\Util\Network;
use Friendica\Util\ParseUrl;
if (preg_match("/\[img\](.*?)\[\/img\]/ism", $attacheddata, $matches)) {
- $picturedata = Image::getInfoFromURL($matches[1]);
+ $picturedata = Images::getInfoFromURLCached($matches[1]);
if ($picturedata) {
if (($picturedata[0] >= 500) && ($picturedata[0] >= $picturedata[1])) {
$post['preview'] = $pictures[0][2];
$post['text'] = trim(str_replace($pictures[0][0], '', $body));
} else {
- $imgdata = Image::getInfoFromURL($pictures[0][1]);
+ $imgdata = Images::getInfoFromURLCached($pictures[0][1]);
if ($imgdata && substr($imgdata['mime'], 0, 6) == 'image/') {
$post['type'] = 'photo';
$post['image'] = $pictures[0][1];
}
// guess mimetype from headers or filename
- $type = Image::guessType($mtch[1], true);
+ $type = Images::guessType($mtch[1], true);
if ($i) {
$Image = new Image($i, $type);
use Friendica\Core\Config\Cache\ConfigCache;
use Friendica\Database\Database;
use Friendica\Database\DBStructure;
-use Friendica\Object\Image;
+use Friendica\Util\Images;
use Friendica\Util\Network;
use Friendica\Util\Strings;
if (class_exists('Imagick')) {
$imagick = true;
- $supported = Image::supportedTypes();
+ $supported = Images::supportedTypes();
if (array_key_exists('image/gif', $supported)) {
$gif = true;
}
use Friendica\Protocol\OStatus;
use Friendica\Protocol\Salmon;
use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Images;
use Friendica\Util\Network;
use Friendica\Util\Strings;
}
// Creating the path to the avatar, beginning with the file suffix
- $types = Image::supportedTypes();
+ $types = Images::supportedTypes();
if (isset($types[$avatar['type']])) {
$file_suffix = $types[$avatar['type']];
}
use Friendica\Database\DBStructure;
use Friendica\Model\Storage\IStorage;
use Friendica\Object\Image;
-use Friendica\Protocol\DFRN;
use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Images;
use Friendica\Util\Network;
use Friendica\Util\Security;
use Friendica\Util\Strings;
}
if (empty($type)) {
- $type = Image::guessType($image_url, true);
+ $type = Images::guessType($image_url, true);
}
$Image = new Image($img_str, $type);
public static function stripExtension($name)
{
$name = str_replace([".jpg", ".png", ".gif"], ["", "", ""], $name);
- foreach (Image::supportedTypes() as $m => $e) {
+ foreach (Images::supportedTypes() as $m => $e) {
$name = str_replace("." . $e, "", $name);
}
return $name;
use Friendica\Object\Image;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Images;
use Friendica\Util\Network;
use Friendica\Util\Strings;
use Friendica\Worker\Delivery;
$filename = basename($photo);
$img_str = Network::fetchUrl($photo, true);
// guess mimetype from headers or filename
- $type = Image::guessType($photo, true);
+ $type = Images::guessType($photo, true);
$Image = new Image($img_str, $type);
if ($Image->isValid()) {
namespace Friendica\Object;
use Exception;
-use Friendica\Core\Cache;
use Friendica\Core\Config;
-use Friendica\Core\Logger;
use Friendica\Core\System;
-use Friendica\Util\Network;
+use Friendica\Util\Images;
use Imagick;
use ImagickPixel;
private $type;
private $types;
- /**
- * @brief supported mimetypes and corresponding file extensions
- * @return array
- */
- public static function supportedTypes()
- {
- if (class_exists('Imagick')) {
- // Imagick::queryFormats won't help us a lot there...
- // At least, not yet, other parts of friendica uses this array
- $t = [
- 'image/jpeg' => 'jpg',
- 'image/png' => 'png',
- 'image/gif' => 'gif'
- ];
- } else {
- $t = [];
- $t['image/jpeg'] ='jpg';
- if (imagetypes() & IMG_PNG) {
- $t['image/png'] = 'png';
- }
- }
-
- return $t;
- }
-
/**
* @brief Constructor
* @param string $data
public function __construct($data, $type = null)
{
$this->imagick = class_exists('Imagick');
- $this->types = static::supportedTypes();
+ $this->types = Images::supportedTypes();
if (!array_key_exists($type, $this->types)) {
- $type='image/jpeg';
+ $type = 'image/jpeg';
}
$this->type = $type;
return $this->imagick;
}
- /**
- * @brief Maps Mime types to Imagick formats
- * @return array With with image formats (mime type as key)
- */
- public static function getFormatsMap()
- {
- $m = [
- 'image/jpeg' => 'JPG',
- 'image/png' => 'PNG',
- 'image/gif' => 'GIF'
- ];
- return $m;
- }
-
/**
* @param string $data data
* @return boolean
/*
* Setup the image to the format it will be saved to
*/
- $map = self::getFormatsMap();
+ $map = Images::getFormatsMap();
$format = $map[$this->type];
$this->image->setFormat($format);
return $string;
}
+ /**
+ * @brief supported mimetypes and corresponding file extensions
+ * @return array
+ * @deprecated in version 2019.12 please use Util\Images::supportedTypes() instead.
+ */
+ public static function supportedTypes()
+ {
+ return Images::supportedTypes();
+ }
+
+ /**
+ * @brief Maps Mime types to Imagick formats
+ * @return array With with image formats (mime type as key)
+ * @deprecated in version 2019.12 please use Util\Images::getFormatsMap() instead.
+ */
+ public static function getFormatsMap()
+ {
+ return Images::getFormatsMap();
+ }
+
/**
* Guess image mimetype from filename or from Content-Type header
*
* @param boolean $fromcurl Check Content-Type header from curl request
* @param string $header passed headers to take into account
*
- * @return object
- * @throws \ImagickException
+ * @return string|null
+ * @throws Exception
+ * @deprecated in version 2019.12 please use Util\Images::guessType() instead.
*/
public static function guessType($filename, $fromcurl = false, $header = '')
{
- Logger::log('Image: guessType: '.$filename . ($fromcurl?' from curl headers':''), Logger::DEBUG);
- $type = null;
- if ($fromcurl) {
- $headers=[];
- $h = explode("\n", $header);
- foreach ($h as $l) {
- $data = array_map("trim", explode(":", trim($l), 2));
- if (count($data) > 1) {
- list($k,$v) = $data;
- $headers[$k] = $v;
- }
- }
- if (array_key_exists('Content-Type', $headers))
- $type = $headers['Content-Type'];
- }
- if (is_null($type)) {
- // Guessing from extension? Isn't that... dangerous?
- if (class_exists('Imagick') && file_exists($filename) && is_readable($filename)) {
- /**
- * Well, this not much better,
- * but at least it comes from the data inside the image,
- * we won't be tricked by a manipulated extension
- */
- $image = new Imagick($filename);
- $type = $image->getImageMimeType();
- $image->setInterlaceScheme(Imagick::INTERLACE_PLANE);
- } else {
- $ext = pathinfo($filename, PATHINFO_EXTENSION);
- $types = self::supportedTypes();
- $type = "image/jpeg";
- foreach ($types as $m => $e) {
- if ($ext == $e) {
- $type = $m;
- }
- }
- }
- }
- Logger::log('Image: guessType: type='.$type, Logger::DEBUG);
- return $type;
+ return Images::guessType($filename, $fromcurl, $header);
}
/**
* @param string $url url
- * @return object
+ * @return array
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @deprecated in version 2019.12 please use Util\Images::getInfoFromURLCached() instead.
*/
public static function getInfoFromURL($url)
{
- $data = [];
-
- if (empty($url)) {
- return $data;
- }
-
- $data = Cache::get($url);
-
- if (is_null($data) || !$data || !is_array($data)) {
- $img_str = Network::fetchUrl($url, true, 4);
-
- if (!$img_str) {
- return false;
- }
-
- $filesize = strlen($img_str);
-
- try {
- if (function_exists("getimagesizefromstring")) {
- $data = @getimagesizefromstring($img_str);
- } else {
- $tempfile = tempnam(get_temppath(), "cache");
-
- $a = \get_app();
- $stamp1 = microtime(true);
- file_put_contents($tempfile, $img_str);
- $a->getProfiler()->saveTimestamp($stamp1, "file", System::callstack());
-
- $data = getimagesize($tempfile);
- unlink($tempfile);
- }
- } catch (Exception $e) {
- return false;
- }
-
- if ($data) {
- $data["size"] = $filesize;
- }
-
- Cache::set($url, $data);
- }
-
- return $data;
+ return Images::getInfoFromURLCached($url);
}
/**
* @param integer $height height
* @param integer $max max
* @return array
+ * @deprecated in version 2019.12 please use Util\Images::getScalingDimensions() instead.
*/
public static function getScalingDimensions($width, $height, $max)
{
- if ((!$width) || (!$height)) {
- return false;
- }
-
- if ($width > $max && $height > $max) {
- // very tall image (greater than 16:9)
- // constrain the width - let the height float.
-
- if ((($height * 9) / 16) > $width) {
- $dest_width = $max;
- $dest_height = intval(($height * $max) / $width);
- } elseif ($width > $height) {
- // else constrain both dimensions
- $dest_width = $max;
- $dest_height = intval(($height * $max) / $width);
- } else {
- $dest_width = intval(($width * $max) / $height);
- $dest_height = $max;
- }
- } else {
- if ($width > $max) {
- $dest_width = $max;
- $dest_height = intval(($height * $max) / $width);
- } else {
- if ($height > $max) {
- // very tall image (greater than 16:9)
- // but width is OK - don't do anything
-
- if ((($height * 9) / 16) > $width) {
- $dest_width = $width;
- $dest_height = $height;
- } else {
- $dest_width = intval(($width * $max) / $height);
- $dest_height = $max;
- }
- } else {
- $dest_width = $width;
- $dest_height = $height;
- }
- }
- }
- return ["width" => $dest_width, "height" => $dest_height];
+ return Images::getScalingDimensions($width, $height, $max);
}
}
use Friendica\BaseObject;
use Friendica\Content\Feature;
-use Friendica\Database\DBA;
+use Friendica\Content\Text\BBCode;
+use Friendica\Content\Text\Plaintext;
+use Friendica\Core\Cache;
use Friendica\Core\Config;
use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\Protocol\Activity;
use Friendica\Util\HTTPSignature;
use Friendica\Core\Protocol;
-use Friendica\Model\Conversation;
-use Friendica\Model\Contact;
+use Friendica\Core\System;
+use Friendica\Database\DBA;
use Friendica\Model\APContact;
+use Friendica\Model\Contact;
+use Friendica\Model\Conversation;
use Friendica\Model\Item;
+use Friendica\Model\Profile;
use Friendica\Model\Term;
use Friendica\Model\User;
+use Friendica\Protocol\ActivityPub;
use Friendica\Util\DateTimeFormat;
-use Friendica\Content\Text\BBCode;
-use Friendica\Content\Text\Plaintext;
-use Friendica\Util\XML;
+use Friendica\Util\HTTPSignature;
+use Friendica\Util\Images;
use Friendica\Util\JsonLD;
use Friendica\Util\LDSignature;
-use Friendica\Model\Profile;
-use Friendica\Object\Image;
-use Friendica\Protocol\ActivityPub;
-use Friendica\Core\Cache;
use Friendica\Util\Map;
use Friendica\Util\Network;
+use Friendica\Util\XML;
require_once 'include/api.php';
require_once 'mod/share.php';
// Grab all pictures without alternative descriptions and create attachments out of them
if (preg_match_all("/\[img\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures)) {
foreach ($pictures[1] as $picture) {
- $imgdata = Image::getInfoFromURL($picture);
+ $imgdata = Images::getInfoFromURLCached($picture);
if ($imgdata) {
$attachments[] = ['type' => 'Document',
'mediaType' => $imgdata['mime'],
// Grab all pictures with alternative description and create attachments out of them
if (preg_match_all("/\[img=([^\[\]]*)\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures, PREG_SET_ORDER)) {
foreach ($pictures as $picture) {
- $imgdata = Image::getInfoFromURL($picture[1]);
+ $imgdata = Images::getInfoFromURLCached($picture[1]);
if ($imgdata) {
$attachments[] = ['type' => 'Document',
'mediaType' => $imgdata['mime'],
use Friendica\Protocol\ActivityNamespace;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Images;
use Friendica\Util\Network;
use Friendica\Util\Strings;
use Friendica\Util\XML;
$uid
);
$photos = [];
- $ext = Image::supportedTypes();
+ $ext = Images::supportedTypes();
foreach ($rp as $p) {
$photos[$p['scale']] = System::baseUrl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']];
use Friendica\Object\Image;
use Friendica\Protocol\ActivityNamespace;
use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Images;
use Friendica\Util\Network;
use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings;
switch ($siteinfo["type"]) {
case 'photo':
if (!empty($siteinfo["image"])) {
- $imgdata = Image::getInfoFromURL($siteinfo["image"]);
+ $imgdata = Images::getInfoFromURLCached($siteinfo["image"]);
if ($imgdata) {
$attributes = ["rel" => "enclosure",
"href" => $siteinfo["image"],
}
if (!Config::get('system', 'ostatus_not_attach_preview') && ($siteinfo["type"] != "photo") && isset($siteinfo["image"])) {
- $imgdata = Image::getInfoFromURL($siteinfo["image"]);
+ $imgdata = Images::getInfoFromURLCached($siteinfo["image"]);
if ($imgdata) {
$attributes = ["rel" => "enclosure",
"href" => $siteinfo["image"],
--- /dev/null
+<?php
+
+namespace Friendica\Util;
+
+use Friendica\BaseObject;
+use Friendica\Core\Cache;
+use Friendica\Core\Logger;
+use Friendica\Core\System;
+use Imagick;
+
+/**
+ * Image utilities
+ */
+class Images
+{
+ /**
+ * Maps Mime types to Imagick formats
+ *
+ * @return array
+ */
+ public static function getFormatsMap()
+ {
+ $m = [
+ 'image/jpeg' => 'JPG',
+ 'image/png' => 'PNG',
+ 'image/gif' => 'GIF'
+ ];
+
+ return $m;
+ }
+
+ /**
+ * Returns supported image mimetypes and corresponding file extensions
+ *
+ * @return array
+ */
+ public static function supportedTypes()
+ {
+ $types = [
+ 'image/jpeg' => 'jpg'
+ ];
+ if (class_exists('Imagick')) {
+ // Imagick::queryFormats won't help us a lot there...
+ // At least, not yet, other parts of friendica uses this array
+ $types += [
+ 'image/png' => 'png',
+ 'image/gif' => 'gif'
+ ];
+ } elseif (imagetypes() & IMG_PNG) {
+ $types += [
+ 'image/png' => 'png'
+ ];
+ }
+
+ return $types;
+ }
+
+ /**
+ * Guess image mimetype from filename or from Content-Type header
+ *
+ * @param string $filename Image filename
+ * @param boolean $fromcurl Check Content-Type header from curl request
+ * @param string $header passed headers to take into account
+ *
+ * @return string|null
+ * @throws \Exception
+ */
+ public static function guessType($filename, $fromcurl = false, $header = '')
+ {
+ Logger::info('Image: guessType: ' . $filename . ($fromcurl ? ' from curl headers' : ''));
+ $type = null;
+ if ($fromcurl) {
+ $headers = [];
+ $h = explode("\n", $header);
+ foreach ($h as $l) {
+ $data = array_map("trim", explode(":", trim($l), 2));
+ if (count($data) > 1) {
+ list($k, $v) = $data;
+ $headers[$k] = $v;
+ }
+ }
+
+ if (array_key_exists('Content-Type', $headers)) {
+ $type = $headers['Content-Type'];
+ }
+ }
+
+ if (is_null($type)) {
+ // Guessing from extension? Isn't that... dangerous?
+ if (class_exists('Imagick') && file_exists($filename) && is_readable($filename)) {
+ /**
+ * Well, this not much better,
+ * but at least it comes from the data inside the image,
+ * we won't be tricked by a manipulated extension
+ */
+ $image = new Imagick($filename);
+ $type = $image->getImageMimeType();
+ } else {
+ $ext = pathinfo($filename, PATHINFO_EXTENSION);
+ $types = self::supportedTypes();
+ $type = 'image/jpeg';
+ foreach ($types as $m => $e) {
+ if ($ext == $e) {
+ $type = $m;
+ }
+ }
+ }
+ }
+
+ Logger::info('Image: guessType: type=' . $type);
+ return $type;
+ }
+
+
+ /**
+ * @param string $url
+ * @return array
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ */
+ public static function getInfoFromURLCached($url)
+ {
+ $data = [];
+
+ if (empty($url)) {
+ return $data;
+ }
+
+ $data = Cache::get($url);
+
+ if (empty($data) || !is_array($data)) {
+ $data = self::getInfoFromURL($url);
+
+ Cache::set($url, $data);
+ }
+
+ return $data;
+ }
+
+ /**
+ * @param string $url
+ * @return array
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ */
+ public static function getInfoFromURL($url)
+ {
+ $data = [];
+
+ if (empty($url)) {
+ return $data;
+ }
+
+ $img_str = Network::fetchUrl($url, true, 4);
+
+ if (!$img_str) {
+ return [];
+ }
+
+ $filesize = strlen($img_str);
+
+ try {
+ if (function_exists("getimagesizefromstring")) {
+ $data = @getimagesizefromstring($img_str);
+ } else {
+ $tempfile = tempnam(get_temppath(), "cache");
+
+ $stamp1 = microtime(true);
+ file_put_contents($tempfile, $img_str);
+ BaseObject::getApp()->getProfiler()->saveTimestamp($stamp1, "file", System::callstack());
+
+ $data = getimagesize($tempfile);
+ unlink($tempfile);
+ }
+ } catch (\Exception $e) {
+ return [];
+ }
+
+ if ($data) {
+ $data['size'] = $filesize;
+ }
+
+ return $data;
+ }
+
+ /**
+ * @param integer $width
+ * @param integer $height
+ * @param integer $max
+ * @return array
+ */
+ public static function getScalingDimensions($width, $height, $max)
+ {
+ if ((!$width) || (!$height)) {
+ return ['width' => 0, 'height' => 0];
+ }
+
+ if ($width > $max && $height > $max) {
+ // very tall image (greater than 16:9)
+ // constrain the width - let the height float.
+
+ if ((($height * 9) / 16) > $width) {
+ $dest_width = $max;
+ $dest_height = intval(($height * $max) / $width);
+ } elseif ($width > $height) {
+ // else constrain both dimensions
+ $dest_width = $max;
+ $dest_height = intval(($height * $max) / $width);
+ } else {
+ $dest_width = intval(($width * $max) / $height);
+ $dest_height = $max;
+ }
+ } else {
+ if ($width > $max) {
+ $dest_width = $max;
+ $dest_height = intval(($height * $max) / $width);
+ } else {
+ if ($height > $max) {
+ // very tall image (greater than 16:9)
+ // but width is OK - don't do anything
+
+ if ((($height * 9) / 16) > $width) {
+ $dest_width = $width;
+ $dest_height = $height;
+ } else {
+ $dest_width = intval(($width * $max) / $height);
+ $dest_height = $max;
+ }
+ } else {
+ $dest_width = $width;
+ $dest_height = $height;
+ }
+ }
+ }
+
+ return ['width' => $dest_width, 'height' => $dest_height];
+ }
+}
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Database\DBA;
-use Friendica\Object\Image;
/**
* @brief Class with methods for extracting certain content from an url
}
$src = self::completeUrl($img_tag['src'], $url);
- $photodata = Image::getInfoFromURL($src);
+ $photodata = Images::getInfoFromURLCached($src);
if (($photodata) && ($photodata[0] > 150) && ($photodata[1] > 150)) {
if ($photodata[0] > 300) {
unset($siteinfo['image']);
- $photodata = Image::getInfoFromURL($src);
+ $photodata = Images::getInfoFromURLCached($src);
if (($photodata) && ($photodata[0] > 10) && ($photodata[1] > 10)) {
$siteinfo['images'][] = ['src' => $src,