当前位置: 首页>>代码示例>>PHP>>正文


PHP Photo::cropImage方法代码示例

本文整理汇总了PHP中Photo::cropImage方法的典型用法代码示例。如果您正苦于以下问题:PHP Photo::cropImage方法的具体用法?PHP Photo::cropImage怎么用?PHP Photo::cropImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Photo的用法示例。


在下文中一共展示了Photo::cropImage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: profile_photo_post

function profile_photo_post(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo');
    if (x($_POST, 'cropfinal') && $_POST['cropfinal'] == 1) {
        // unless proven otherwise
        $is_default_profile = 1;
        if ($_REQUEST['profile']) {
            $r = q("select id, `is-default` from profile where id = %d and uid = %d limit 1", intval($_REQUEST['profile']), intval(local_user()));
            if (count($r) && !intval($r[0]['is-default'])) {
                $is_default_profile = 0;
            }
        }
        // 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 `uid` = %d AND `scale` = %d LIMIT 1", dbesc($image_id), dbesc(local_user()), intval($scale));
        if (count($r)) {
            $base_image = $r[0];
            $im = new Photo($base_image['data'], $base_image['type']);
            if ($im->is_valid()) {
                $im->cropImage(175, $srcX, $srcY, $srcW, $srcH);
                $r = $im->store(local_user(), 0, $base_image['resource-id'], $base_image['filename'], t('Profile Photos'), 4, $is_default_profile);
                if ($r === false) {
                    notice(sprintf(t('Image size reduction [%s] failed.'), "175") . EOL);
                }
                $im->scaleImage(80);
                $r = $im->store(local_user(), 0, $base_image['resource-id'], $base_image['filename'], t('Profile Photos'), 5, $is_default_profile);
                if ($r === false) {
                    notice(sprintf(t('Image size reduction [%s] failed.'), "80") . EOL);
                }
                $im->scaleImage(48);
                $r = $im->store(local_user(), 0, $base_image['resource-id'], $base_image['filename'], t('Profile Photos'), 6, $is_default_profile);
                if ($r === false) {
                    notice(sprintf(t('Image size reduction [%s] failed.'), "48") . EOL);
                }
                // If setting for the default profile, unset the profile photo flag from any other photos I own
                if ($is_default_profile) {
                    $r = q("UPDATE `photo` SET `profile` = 0 WHERE `profile` = 1 AND `resource-id` != '%s' AND `uid` = %d", dbesc($base_image['resource-id']), intval(local_user()));
                    $r = q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s'  WHERE `self` AND `uid` = %d", dbesc($a->get_baseurl() . '/photo/' . $base_image['resource-id'] . '-4.' . $im->getExt()), dbesc($a->get_baseurl() . '/photo/' . $base_image['resource-id'] . '-5.' . $im->getExt()), dbesc($a->get_baseurl() . '/photo/' . $base_image['resource-id'] . '-6.' . $im->getExt()), intval(local_user()));
                } else {
                    $r = q("update profile set photo = '%s', thumb = '%s' where id = %d and uid = %d", dbesc($a->get_baseurl() . '/photo/' . $base_image['resource-id'] . '-4.' . $im->getExt()), dbesc($a->get_baseurl() . '/photo/' . $base_image['resource-id'] . '-5.' . $im->getExt()), intval($_REQUEST['profile']), intval(local_user()));
                }
                // we'll set the updated profile-photo timestamp even if it isn't the default profile,
                // so that browsers will do a cache update unconditionally
                $r = q("UPDATE `contact` SET `avatar-date` = '%s' WHERE `self` = 1 AND `uid` = %d", dbesc(datetime_convert()), intval(local_user()));
                info(t('Shift-reload the page or clear browser cache if the new photo does not display immediately.') . EOL);
                // Update global directory in background
                $url = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
                if ($url && strlen(get_config('system', 'directory'))) {
                    proc_run('php', "include/directory.php", "{$url}");
                }
                require_once 'include/profile_update.php';
                profile_change();
            } else {
                notice(t('Unable to process image') . EOL);
            }
        }
        goaway($a->get_baseurl() . '/profiles');
        return;
        // NOTREACHED
    }
    $src = $_FILES['userfile']['tmp_name'];
    $filename = basename($_FILES['userfile']['name']);
    $filesize = intval($_FILES['userfile']['size']);
    $filetype = $_FILES['userfile']['type'];
    if ($filetype == "") {
        $filetype = guess_image_type($filename);
    }
    $maximagesize = get_config('system', 'maximagesize');
    if ($maximagesize && $filesize > $maximagesize) {
        notice(sprintf(t('Image exceeds size limit of %s'), formatBytes($maximagesize)) . EOL);
        @unlink($src);
        return;
    }
    $imagedata = @file_get_contents($src);
    $ph = new Photo($imagedata, $filetype);
    if (!$ph->is_valid()) {
        notice(t('Unable to process image.') . EOL);
        @unlink($src);
        return;
    }
    $ph->orient($src);
    @unlink($src);
    return profile_photo_crop_ui_head($a, $ph);
}
开发者ID:vinzv,项目名称:friendica,代码行数:100,代码来源:profile_photo.php

示例2: profile_photo_post

function profile_photo_post(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo');
    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 `uid` = %d AND `scale` = %d LIMIT 1", dbesc($image_id), dbesc(local_user()), intval($scale));
        if (count($r)) {
            $base_image = $r[0];
            $im = new Photo($base_image['data']);
            if ($im->is_valid()) {
                $im->cropImage(175, $srcX, $srcY, $srcW, $srcH);
                $r = $im->store(local_user(), 0, $base_image['resource-id'], $base_image['filename'], t('Profile Photos'), 4, 1);
                if ($r === false) {
                    notice(sprintf(t('Image size reduction [%s] failed.'), "175") . EOL);
                }
                $im->scaleImage(80);
                $r = $im->store(local_user(), 0, $base_image['resource-id'], $base_image['filename'], t('Profile Photos'), 5, 1);
                if ($r === false) {
                    notice(sprintf(t('Image size reduction [%s] failed.'), "80") . EOL);
                }
                $im->scaleImage(48);
                $r = $im->store(local_user(), 0, $base_image['resource-id'], $base_image['filename'], t('Profile Photos'), 6, 1);
                if ($r === false) {
                    notice(sprintf(t('Image size reduction [%s] failed.'), "48") . 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' AND `uid` = %d", dbesc($base_image['resource-id']), intval(local_user()));
                $r = q("UPDATE `contact` SET `avatar-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1", dbesc(datetime_convert()), intval(local_user()));
                info(t('Shift-reload the page or clear browser cache if the new photo does not display immediately.') . EOL);
                // Update global directory in background
                $url = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
                if ($url && strlen(get_config('system', 'directory_submit_url'))) {
                    proc_run('php', "include/directory.php", "{$url}");
                }
                require_once 'include/profile_update.php';
                profile_change();
            } else {
                notice(t('Unable to process image') . EOL);
            }
        }
        goaway($a->get_baseurl() . '/profiles');
        return;
        // NOTREACHED
    }
    $src = $_FILES['userfile']['tmp_name'];
    $filename = basename($_FILES['userfile']['name']);
    $filesize = intval($_FILES['userfile']['size']);
    $maximagesize = get_config('system', 'maximagesize');
    if ($maximagesize && $filesize > $maximagesize) {
        notice(sprintf(t('Image exceeds size limit of %d'), $maximagesize) . EOL);
        @unlink($src);
        return;
    }
    $imagedata = @file_get_contents($src);
    $ph = new Photo($imagedata);
    if (!$ph->is_valid()) {
        notice(t('Unable to process image.') . EOL);
        @unlink($src);
        return;
    }
    @unlink($src);
    return profile_photo_crop_ui_head($a, $ph);
}
开发者ID:robhell,项目名称:friendica,代码行数:80,代码来源:profile_photo.php

示例3: store_photo


//.........这里部分代码省略.........
    }
    /*
            $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
                    intval($uid)
            );
    
            $limit = service_class_fetch($uid,'photo_upload_limit');
    
            if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
    		logger("Image exceeds personal limit of uid ".$uid, LOGGER_DEBUG);
    		return(array());
            }
    */
    $tempfile = tempnam(get_temppath(), "cache");
    file_put_contents($tempfile, $imagedata);
    $data = getimagesize($tempfile);
    if (!isset($data["mime"])) {
        unlink($tempfile);
        logger("File is no picture", LOGGER_DEBUG);
        return array();
    }
    $ph = new Photo($imagedata, $data["mime"]);
    if (!$ph->is_valid()) {
        unlink($tempfile);
        logger("Picture is no valid picture", LOGGER_DEBUG);
        return array();
    }
    $ph->orient($tempfile);
    unlink($tempfile);
    $max_length = get_config('system', 'max_image_length');
    if (!$max_length) {
        $max_length = MAX_IMAGE_LENGTH;
    }
    if ($max_length > 0) {
        $ph->scaleImage($max_length);
    }
    $width = $ph->getWidth();
    $height = $ph->getHeight();
    $hash = photo_new_resource();
    $smallest = 0;
    // Pictures are always public by now
    //$defperm = '<'.$default_cid.'>';
    $defperm = "";
    $visitor = 0;
    $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 0, 0, $defperm);
    if (!$r) {
        logger("Picture couldn't be stored", LOGGER_DEBUG);
        return array();
    }
    $image = array("page" => $a->get_baseurl() . '/photos/' . $page_owner_nick . '/image/' . $hash, "full" => $a->get_baseurl() . "/photo/{$hash}-0." . $ph->getExt());
    if ($width > 800 || $height > 800) {
        $image["large"] = $a->get_baseurl() . "/photo/{$hash}-0." . $ph->getExt();
    }
    if ($width > 640 || $height > 640) {
        $ph->scaleImage(640);
        $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 1, 0, $defperm);
        if ($r) {
            $image["medium"] = $a->get_baseurl() . "/photo/{$hash}-1." . $ph->getExt();
        }
    }
    if ($width > 320 || $height > 320) {
        $ph->scaleImage(320);
        $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 2, 0, $defperm);
        if ($r) {
            $image["small"] = $a->get_baseurl() . "/photo/{$hash}-2." . $ph->getExt();
        }
    }
    if ($width > 160 and $height > 160) {
        $x = 0;
        $y = 0;
        $min = $ph->getWidth();
        if ($min > 160) {
            $x = ($min - 160) / 2;
        }
        if ($ph->getHeight() < $min) {
            $min = $ph->getHeight();
            if ($min > 160) {
                $y = ($min - 160) / 2;
            }
        }
        $min = 160;
        $ph->cropImage(160, $x, $y, $min, $min);
        $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 3, 0, $defperm);
        if ($r) {
            $image["thumb"] = $a->get_baseurl() . "/photo/{$hash}-3." . $ph->getExt();
        }
    }
    // Set the full image as preview image. This will be overwritten, if the picture is larger than 640.
    $image["preview"] = $image["full"];
    // Deactivated, since that would result in a cropped preview, if the picture wasn't larger than 320
    //if (isset($image["thumb"]))
    //	$image["preview"] = $image["thumb"];
    // Unsure, if this should be activated or deactivated
    //if (isset($image["small"]))
    //	$image["preview"] = $image["small"];
    if (isset($image["medium"])) {
        $image["preview"] = $image["medium"];
    }
    return $image;
}
开发者ID:jzacman,项目名称:friendica,代码行数:101,代码来源:Photo.php

示例4: 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;
}
开发者ID:vishalp,项目名称:MistparkPE-Remix,代码行数:89,代码来源:profile_photo.php


注:本文中的Photo::cropImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。