Photo to src
This commit is contained in:
Hypolite Petovan 2017-11-30 20:33:48 -05:00 committed by GitHub
commit 0ae6f571da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 742 additions and 600 deletions

File diff suppressed because it is too large Load diff

View file

@ -5,7 +5,6 @@
*
* @todo Automatically detect if incoming data is HTML or BBCode
*/
use Friendica\App;
use Friendica\Core\System;
use Friendica\Core\Config;
@ -23,6 +22,7 @@ use Friendica\Network\HTTPException\NotImplementedException;
use Friendica\Network\HTTPException\UnauthorizedException;
use Friendica\Network\HTTPException\TooManyRequestsException;
use Friendica\Object\Contact;
use Friendica\Object\Photo;
use Friendica\Protocol\Diaspora;
use Friendica\Util\XML;
@ -32,7 +32,6 @@ require_once 'include/conversation.php';
require_once 'include/oauth.php';
require_once 'include/html2plain.php';
require_once 'mod/share.php';
require_once 'include/Photo.php';
require_once 'mod/item.php';
require_once 'include/security.php';
require_once 'include/contact_selectors.php';
@ -2377,7 +2376,7 @@ function api_get_attachments(&$body)
$attachments = array();
foreach ($images[1] as $image) {
$imagedata = get_photo_info($image);
$imagedata = Photo::getInfoFromURL($image);
if ($imagedata) {
$attachments[] = array("url" => $image, "mimetype" => $imagedata["mime"], "size" => $imagedata["size"]);
@ -2509,7 +2508,7 @@ function api_get_entitities(&$text, $bbcode)
$start = iconv_strpos($text, $url, $offset, "UTF-8");
if (!($start === false)) {
$image = get_photo_info($url);
$image = Photo::getInfoFromURL($url);
if ($image) {
// If image cache is activated, then use the following sizes:
// thumb (150), small (340), medium (600) and large (1024)
@ -2517,19 +2516,19 @@ function api_get_entitities(&$text, $bbcode)
$media_url = proxy_url($url);
$sizes = array();
$scale = scale_image($image[0], $image[1], 150);
$scale = Photo::scaleImageTo($image[0], $image[1], 150);
$sizes["thumb"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
if (($image[0] > 150) || ($image[1] > 150)) {
$scale = scale_image($image[0], $image[1], 340);
$scale = Photo::scaleImageTo($image[0], $image[1], 340);
$sizes["small"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
}
$scale = scale_image($image[0], $image[1], 600);
$scale = Photo::scaleImageTo($image[0], $image[1], 600);
$sizes["medium"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
if (($image[0] > 600) || ($image[1] > 600)) {
$scale = scale_image($image[0], $image[1], 1024);
$scale = Photo::scaleImageTo($image[0], $image[1], 1024);
$sizes["large"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
}
} else {
@ -3946,7 +3945,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
}
if ($filetype == "") {
$filetype=guess_image_type($filename);
$filetype=Photo::guessImageType($filename);
}
$imagedata = getimagesize($src);
if ($imagedata) {
@ -3971,7 +3970,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
// create Photo instance with the data of the image
$imagedata = @file_get_contents($src);
$ph = new Photo($imagedata, $filetype);
if (! $ph->is_valid()) {
if (! $ph->isValid()) {
throw new InternalServerErrorException("unable to process image data");
}

View file

@ -8,13 +8,13 @@ use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Network\Probe;
use Friendica\Object\Contact;
use Friendica\Protocol\Diaspora;
use Friendica\Protocol\OStatus;
use Friendica\Protocol\PortableContact;
require_once 'include/group.php';
require_once 'include/salmon.php';
require_once 'include/Photo.php';
function update_contact($id) {
/*
@ -250,7 +250,7 @@ function new_contact($uid, $url, $interactive = false, $network = '') {
}
// Update the avatar
update_contact_avatar($ret['photo'],$uid,$contact_id);
Contact::updateAvatar($ret['photo'], $uid, $contact_id);
// pull feed and consume it, which should subscribe to the hub.

View file

@ -1,9 +1,7 @@
<?php
/**
* @file include/items.php
*/
use Friendica\App;
use Friendica\ParseUrl;
use Friendica\Core\Config;
@ -21,7 +19,6 @@ require_once 'include/bbcode.php';
require_once 'include/oembed.php';
require_once 'include/salmon.php';
require_once 'include/crypto.php';
require_once 'include/Photo.php';
require_once 'include/tags.php';
require_once 'include/files.php';
require_once 'include/text.php';
@ -1692,7 +1689,7 @@ function new_follower($importer, $contact, $datarray, $item, $sharing = false) {
);
if (DBM::is_result($r)) {
$contact_record = $r[0];
update_contact_avatar($photo, $importer["uid"], $contact_record["id"], true);
Contact::updateAvatar($photo, $importer["uid"], $contact_record["id"], true);
}
/// @TODO Encapsulate this into a function/method
@ -1879,7 +1876,7 @@ function fix_private_photos($s, $uid, $item = null, $cid = 0) {
$height = intval($match[2]);
$ph = new Photo($data, $type);
if ($ph->is_valid()) {
if ($ph->isValid()) {
$ph->scaleImage(max($width, $height));
$data = $ph->imageString();
$type = $ph->getType();

View file

@ -1,13 +1,12 @@
<?php
/**
* @file include/network.php
*/
use Friendica\App;
use Friendica\Core\System;
use Friendica\Core\Config;
use Friendica\Network\Probe;
use Friendica\Object\Photo;
use Friendica\Util\XML;
/**
@ -687,7 +686,6 @@ function scale_external_images($srctext, $include_link = true, $scale_replace =
$matches = null;
$c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism', $s, $matches, PREG_SET_ORDER);
if ($c) {
require_once 'include/Photo.php';
foreach ($matches as $mtch) {
logger('scale_external_image: ' . $mtch[1]);
@ -712,11 +710,11 @@ function scale_external_images($srctext, $include_link = true, $scale_replace =
}
// guess mimetype from headers or filename
$type = guess_image_type($mtch[1], true);
$type = Photo::guessImageType($mtch[1], true);
if ($i) {
$ph = new Photo($i, $type);
if ($ph->is_valid()) {
if ($ph->isValid()) {
$orig_width = $ph->getWidth();
$orig_height = $ph->getHeight();

View file

@ -1,17 +1,15 @@
<?php
/**
* @file include/plaintext.php
*/
use Friendica\App;
use Friendica\ParseUrl;
use Friendica\Core\PConfig;
use Friendica\Object\Photo;
require_once("include/Photo.php");
require_once("include/bbcode.php");
require_once("include/html2plain.php");
require_once("include/network.php");
require_once "include/bbcode.php";
require_once "include/html2plain.php";
require_once "include/network.php";
/**
* @brief Fetches attachment data that were generated the old way
@ -53,7 +51,7 @@ function get_old_attachment_data($body) {
if (preg_match("/\[img\]([$URLSearchString]*)\[\/img\]/ism", $attacheddata, $matches)) {
$picturedata = get_photo_info($matches[1]);
$picturedata = Photo::getInfoFromURL($matches[1]);
if (($picturedata[0] >= 500) && ($picturedata[0] >= $picturedata[1]))
$post["image"] = $matches[1];
@ -223,7 +221,7 @@ function get_attached_data($body, $item = array()) {
$post["preview"] = $pictures[0][2];
$post["text"] = str_replace($pictures[0][0], "", $body);
} else {
$imgdata = get_photo_info($pictures[0][1]);
$imgdata = Photo::getInfoFromURL($pictures[0][1]);
if (substr($imgdata["mime"], 0, 6) == "image/") {
$post["type"] = "photo";
$post["image"] = $pictures[0][1];

View file

@ -1,12 +1,14 @@
<?php
/**
* @file include/uimport.php
*/
use Friendica\App;
use Friendica\Core\System;
use Friendica\Core\PConfig;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Object\Photo;
require_once("include/Photo.php");
define("IMPORT_DEBUG", False);
function last_insert_id() {

View file

@ -1,8 +1,11 @@
<?php
/**
* @file include/user.php
*/
use Friendica\Core\Config;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Object\Photo;
require_once 'include/network.php';
require_once 'include/plugin.php';
@ -282,24 +285,22 @@ function create_user($arr) {
$photo = avatar_img($email);
// unless there is no avatar-plugin loaded
if(strlen($photo)) {
require_once('include/Photo.php');
if (strlen($photo)) {
$photo_failure = false;
$filename = basename($photo);
$img_str = fetch_url($photo,true);
$img_str = fetch_url($photo, true);
// guess mimetype from headers or filename
$type = guess_image_type($photo,true);
$type = Photo::guessImageType($photo, true);
$img = new Photo($img_str, $type);
if($img->is_valid()) {
if ($img->isValid()) {
$img->scaleImageSquare(175);
$hash = photo_new_resource();
$r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 4 );
$r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 4);
if ($r === false) {
$photo_failure = true;