本文整理汇总了PHP中Photo::getImage方法的典型用法代码示例。如果您正苦于以下问题:PHP Photo::getImage方法的具体用法?PHP Photo::getImage怎么用?PHP Photo::getImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Photo
的用法示例。
在下文中一共展示了Photo::getImage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wall_upload_post
function wall_upload_post(&$a)
{
if (!local_user()) {
echo t('Permission denied.') . EOL;
killme();
}
if (!x($_FILES, 'userfile')) {
killme();
}
$src = $_FILES['userfile']['tmp_name'];
$filename = basename($_FILES['userfile']['name']);
$filesize = intval($_FILES['userfile']['size']);
$imagedata = @file_get_contents($src);
$ph = new Photo($imagedata);
if (!($image = $ph->getImage())) {
echo t('Unable to process image.') . EOL;
@unlink($src);
killme();
}
@unlink($src);
$width = $ph->getWidth();
$height = $ph->getHeight();
$hash = hash('md5', uniqid(mt_rand(), true));
$smallest = 0;
$r = $ph->store(0, $hash, $filename, t('Wall Photos'), 0);
if (!$r) {
echo t('Image upload failed.') . EOL;
killme();
}
if ($width > 640 || $height > 640) {
$ph->scaleImage(640);
$r = $ph->store(0, $hash, $filename, t('Wall Photos'), 1);
if ($r) {
$smallest = 1;
}
}
if ($width > 320 || $height > 320) {
$ph->scaleImage(320);
$r = $ph->store(0, $hash, $filename, t('Wall Photos'), 2);
if ($r) {
$smallest = 2;
}
}
$basename = basename($filename);
echo "<br /><br /><img src=\"" . $a->get_baseurl() . "/photo/{$hash}-{$smallest}.jpg\" alt=\"{$basename}\" /><br /><br />";
killme();
return;
// NOTREACHED
}
示例2: photos_post
//.........这里部分代码省略.........
if (count($r)) {
$r = q("UPDATE `photo` SET `desc` = '%s' WHERE `resource-id` = '%s' ", dbesc($desc), dbesc($resource_id));
}
if (!$item_id) {
$title = '';
$basename = basename($filename);
// Create item container
$body = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]' . '[/url]';
$uri = item_new_uri($a->get_hostname(), get_uid());
$r = q("INSERT INTO `item` (`type`, `wall`, `resource-id`, `contact-id`,\n\t\t\t\t`owner-name`,`owner-link`,`owner-avatar`, `created`,\n\t\t\t\t`edited`, `changed`, `uri`, `parent-uri`, `title`, `body`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`)\n\t\t\t\tVALUES( '%s', %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )", dbesc('photo'), intval(1), dbesc($p[0]['resource-id']), intval($contact_record['id']), dbesc($contact_record['name']), dbesc($contact_record['url']), dbesc($contact_record['thumb']), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc($uri), dbesc($uri), dbesc($title), dbesc($body), dbesc($p[0]['allow_cid']), dbesc($p[0]['allow_gid']), dbesc($p[0]['deny_cid']), dbesc($p[0]['deny_gid']));
if ($r) {
$r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($uri));
if (count($r)) {
$item_id = $r[0]['id'];
}
q("UPDATE `item` SET `parent` = %d, `last-child` = 1 WHERE `id` = %d LIMIT 1", intval($r[0]['id']), intval($r[0]['id']));
}
}
$r = q("UPDATE `item` SET `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1", dbesc($tags), dbesc(datetime_convert()), dbesc(datetime_convert()), intval($item_id));
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
return;
// NOTREACHED
}
if (!x($_FILES, 'userfile')) {
killme();
}
if ($_POST['partitionCount']) {
$java_upload = true;
} else {
$java_upload = false;
}
$album = notags(trim($_POST['album']));
$newalbum = notags(trim($_POST['newalbum']));
if (!strlen($album)) {
if (strlen($newalbum)) {
$album = $newalbum;
} else {
$album = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
}
}
$r = q("SELECT * FROM `photo` WHERE `album` = '%s' ", dbesc($album));
if (!count($r) || $album == t('Profile Photos')) {
$visible = 1;
} else {
$visibile = 0;
}
$str_group_allow = perms2str($_POST['group_allow']);
$str_contact_allow = perms2str($_POST['contact_allow']);
$str_group_deny = perms2str($_POST['group_deny']);
$str_contact_deny = perms2str($_POST['contact_deny']);
$src = $_FILES['userfile']['tmp_name'];
$filename = basename($_FILES['userfile']['name']);
$filesize = intval($_FILES['userfile']['size']);
$imagedata = @file_get_contents($src);
$ph = new Photo($imagedata);
if (!($image = $ph->getImage())) {
notice(t('Unable to process image.') . EOL);
@unlink($src);
killme();
}
@unlink($src);
$width = $ph->getWidth();
$height = $ph->getHeight();
$smallest = 0;
$photo_hash = hash('md5', uniqid(mt_rand(), true));
$r = $ph->store(0, $photo_hash, $filename, $album, 0, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
if (!$r) {
notice(t('Image upload failed.') . EOL);
killme();
}
if ($width > 640 || $height > 640) {
$ph->scaleImage(640);
$ph->store(0, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
$smallest = 1;
}
if ($width > 320 || $height > 320) {
$ph->scaleImage(320);
$ph->store(0, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
$smallest = 2;
}
$basename = basename($filename);
// Create item container
$body = '[url=' . $a->get_baseurl() . '/photos/' . $contact_record['nickname'] . '/image/' . $photo_hash . ']' . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]' . '[/url]';
$uri = item_new_uri($a->get_hostname(), get_uid());
$r = q("INSERT INTO `item` (`type`, `wall`, `resource-id`, `contact-id`,`owner-name`,`owner-link`,`owner-avatar`, `created`,\n\t\t`edited`, `changed`, `uri`, `parent-uri`, `title`, `body`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `visible`)\n\t\tVALUES( '%s', %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d )", dbesc('photo'), intval(1), dbesc($photo_hash), intval($contact_record['id']), dbesc($contact_record['name']), dbesc($contact_record['url']), dbesc($contact_record['thumb']), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc($uri), dbesc($uri), dbesc($title), dbesc($body), dbesc($str_contact_allow), dbesc($str_group_allow), dbesc($str_contact_deny), dbesc($str_group_deny), intval($visible));
if ($r) {
$r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($uri));
if (count($r)) {
q("UPDATE `item` SET `parent` = %d, `last-child` = 1 WHERE `id` = %d LIMIT 1", intval($r[0]['id']), intval($r[0]['id']));
}
}
if (!$java_upload) {
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
return;
// NOTREACHED
}
killme();
return;
// NOTREACHED
}
示例3: profile_photo_post
function profile_photo_post(&$a)
{
if (!local_user()) {
notice(t('Permission denied.') . EOL);
return;
}
if (x($_POST, 'cropfinal') && $_POST['cropfinal'] == 1) {
// phase 2 - we have finished cropping
if ($a->argc != 2) {
notice(t('Image uploaded but image cropping failed.') . EOL);
return;
}
$image_id = $a->argv[1];
if (substr($image_id, -2, 1) == '-') {
$scale = substr($image_id, -1, 1);
$image_id = substr($image_id, 0, -2);
}
$srcX = $_POST['xstart'];
$srcY = $_POST['ystart'];
$srcW = $_POST['xfinal'] - $srcX;
$srcH = $_POST['yfinal'] - $srcY;
$r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d LIMIT 1", dbesc($image_id), intval($scale));
if (count($r)) {
$base_image = $r[0];
$im = new Photo($base_image['data']);
$im->cropImage(175, $srcX, $srcY, $srcW, $srcH);
$r = $im->store(0, $base_image['resource-id'], $base_image['filename'], t('Profile Photos'), 4, 1);
if ($r === false) {
notice(t('Image size reduction (175) failed.') . EOL);
}
$im->scaleImage(80);
$r = $im->store(0, $base_image['resource-id'], $base_image['filename'], t('Profile Photos'), 5, 1);
if ($r === false) {
notice(t('Image size reduction (80) failed.') . EOL);
}
// Unset the profile photo flag from any other photos I own
$r = q("UPDATE `photo` SET `profile` = 0 WHERE `profile` = 1 AND `resource-id` != '%s' ", dbesc($base_image['resource-id']));
$r = q("UPDATE `contact` SET `avatar-date` = '%s' WHERE `self` = 1 LIMIT 1", dbesc(datetime_convert()));
// Update global directory in background
$php_path = strlen($a->config['php_path']) ? $a->config['php_path'] : 'php';
$url = $_SESSION['my_url'];
if ($url && strlen(get_config('system', 'directory_submit_url'))) {
proc_close(proc_open("\"{$php_path}\" \"include/directory.php\" \"{$url}\" &", array(), $foo));
}
}
goaway($a->get_baseurl() . '/profiles');
return;
// NOTREACHED
}
$src = $_FILES['userfile']['tmp_name'];
$filename = basename($_FILES['userfile']['name']);
$filesize = intval($_FILES['userfile']['size']);
$imagedata = @file_get_contents($src);
$ph = new Photo($imagedata);
if (!($image = $ph->getImage())) {
notice(t('Unable to process image.') . EOL);
@unlink($src);
return;
}
@unlink($src);
$width = $ph->getWidth();
$height = $ph->getHeight();
if ($width < 175 || $height < 175) {
$ph->scaleImageUp(200);
$width = $ph->getWidth();
$height = $ph->getHeight();
}
$hash = hash('md5', uniqid(mt_rand(), true));
$smallest = 0;
$r = $ph->store(0, $hash, $filename, t('Profile Photos'), 0);
if ($r) {
notice(t('Image uploaded successfully.') . EOL);
} else {
notice(t('Image upload failed.') . EOL);
}
if ($width > 640 || $height > 640) {
$ph->scaleImage(640);
$r = $ph->store(0, $hash, $filename, t('Profile Photos'), 1);
if ($r === false) {
notice(t('Image size reduction (640) failed.') . EOL);
} else {
$smallest = 1;
}
}
$a->config['imagecrop'] = $hash;
$a->config['imagecrop_resolution'] = $smallest;
$a->page['htmlhead'] .= file_get_contents("view/crophead.tpl");
return;
}