• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP get_resized_image_from_existing_file函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中get_resized_image_from_existing_file函数的典型用法代码示例。如果您正苦于以下问题:PHP get_resized_image_from_existing_file函数的具体用法?PHP get_resized_image_from_existing_file怎么用?PHP get_resized_image_from_existing_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: zhsocial_apply_icon

function zhsocial_apply_icon($zh_user, $icon_url)
{
    // 	if($zh_user->icontime)
    // 		return;
    $icon_sizes = elgg_get_config('icon_sizes');
    $prefix = "profile/{$zh_user->guid}";
    $filehandler = new ElggFile();
    $filehandler->owner_guid = $zh_user->guid;
    $filehandler->setFilename($prefix . ".jpg");
    $filehandler->open("write");
    $filehandler->write(file_get_contents($icon_url));
    $filehandler->close();
    $filename = $filehandler->getFilenameOnFilestore();
    $sizes = array('topbar', 'tiny', 'small', 'medium', 'large', 'master');
    $thumbs = array();
    foreach ($sizes as $size) {
        $thumbs[$size] = get_resized_image_from_existing_file($filename, $icon_sizes[$size]['w'], $icon_sizes[$size]['h'], $icon_sizes[$size]['square']);
    }
    if ($thumbs['tiny']) {
        // just checking if resize successful
        $thumb = new ElggFile();
        $thumb->owner_guid = $zh_user->guid;
        $thumb->setMimeType('image/jpeg');
        foreach ($sizes as $size) {
            $thumb->setFilename("{$prefix}{$size}.jpg");
            $thumb->open("write");
            $thumb->write($thumbs[$size]);
            $thumb->close();
        }
        $zh_user->icontime = time();
    }
}
开发者ID:pingwangcs,项目名称:51zhaohu,代码行数:32,代码来源:start.php


示例2: form_generate_thumbnail

function form_generate_thumbnail($file, $fieldname)
{
    // Generate thumbnail (if image)
    $prefix = "file/";
    $filestorename = strtolower(time() . $_FILES[$fieldname]['name']);
    if (substr_count($file->getMimeType(), 'image/')) {
        $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 60, 60, true);
        $thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 153, 153, true);
        $thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 600, 600, false);
        if ($thumbnail) {
            $thumb = new ElggFile();
            $thumb->setMimeType($_FILES[$fieldname]['type']);
            $thumb->setFilename($prefix . "thumb" . $filestorename);
            $thumb->open("write");
            $thumb->write($thumbnail);
            $thumb->close();
            $file->thumbnail = $prefix . "thumb" . $filestorename;
            $thumb->setFilename($prefix . "smallthumb" . $filestorename);
            $thumb->open("write");
            $thumb->write($thumbsmall);
            $thumb->close();
            $file->smallthumb = $prefix . "smallthumb" . $filestorename;
            $thumb->setFilename($prefix . "largethumb" . $filestorename);
            $thumb->open("write");
            $thumb->write($thumblarge);
            $thumb->close();
            $file->largethumb = $prefix . "largethumb" . $filestorename;
        }
    }
}
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:30,代码来源:model.php


示例3: pleiofile_generate_file_thumbs

function pleiofile_generate_file_thumbs(ElggObject $file)
{
    if ($file->simpletype != "image") {
        return null;
    }
    $file->icontime = time();
    $sizes = array(60 => "thumb", 153 => "tinythumb", 153 => "smallthumb", 600 => "largethumb");
    $filename = str_replace("file/", "", $file->getFilename());
    foreach ($sizes as $size => $description) {
        if ($size < 600) {
            $upscale = true;
        } else {
            $upscale = false;
        }
        $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), $size, $size, $upscale);
        if ($thumbnail) {
            $path = "file/" . $description . "_" . $filename;
            $thumb = new ElggFile();
            $thumb->setMimeType($_FILES['upload']['type']);
            $thumb->setFilename($path);
            $thumb->open("write");
            $thumb->write($thumbnail);
            $thumb->close();
            if ($description == "thumb") {
                $file->thumbnail = $path;
            } else {
                $file->{$description} = $path;
            }
            unset($thumbnail);
        }
    }
}
开发者ID:pleio,项目名称:pleiofile,代码行数:32,代码来源:functions.php


示例4: get_resized_image_from_uploaded_file

/**
 * Gets the jpeg contents of the resized version of an uploaded image
 * (Returns false if the uploaded file was not an image)
 *
 * @param string $input_name The name of the file input field on the submission form
 * @param int    $maxwidth   The maximum width of the resized image
 * @param int    $maxheight  The maximum height of the resized image
 * @param bool   $square     If set to true, will take the smallest
 *                           of maxwidth and maxheight and use it to set the
 *                           dimensions on all size; the image will be cropped.
 * @param bool   $upscale    Resize images smaller than $maxwidth x $maxheight?
 *
 * @return false|mixed The contents of the resized image, or false on failure
 */
function get_resized_image_from_uploaded_file($input_name, $maxwidth, $maxheight, $square = false, $upscale = false)
{
    // If our file exists ...
    if (isset($_FILES[$input_name]) && $_FILES[$input_name]['error'] == 0) {
        return get_resized_image_from_existing_file($_FILES[$input_name]['tmp_name'], $maxwidth, $maxheight, $square, 0, 0, 0, 0, $upscale);
    }
    return false;
}
开发者ID:rcolomoc,项目名称:Master-Red-Social,代码行数:22,代码来源:filestore.php


示例5: get_resized_image_from_uploaded_file

/**
 * Gets the jpeg contents of the resized version of an uploaded image
 * (Returns false if the uploaded file was not an image)
 *
 * @param string $input_name The name of the file input field on the submission form
 * @param int    $maxwidth   The maximum width of the resized image
 * @param int    $maxheight  The maximum height of the resized image
 * @param bool   $square     If set to true, will take the smallest
 *                           of maxwidth and maxheight and use it to set the
 *                           dimensions on all size; the image will be cropped.
 * @param bool   $upscale    Resize images smaller than $maxwidth x $maxheight?
 *
 * @return false|mixed The contents of the resized image, or false on failure
 */
function get_resized_image_from_uploaded_file($input_name, $maxwidth, $maxheight, $square = false, $upscale = false)
{
    $files = _elgg_services()->request->files;
    if (!$files->has($input_name)) {
        return false;
    }
    $file = $files->get($input_name);
    if (elgg_extract('error', $file) !== 0) {
        return false;
    }
    return get_resized_image_from_existing_file(elgg_extract('tmp_name', $file), $maxwidth, $maxheight, $square, 0, 0, 0, 0, $upscale);
}
开发者ID:gzachos,项目名称:elgg_ellak,代码行数:26,代码来源:filestore.php


示例6: CreateLTIGroup

function CreateLTIGroup($user, $name, $context_id, $consumer_key)
{
    $group_guid = 0;
    $group = new ElggGroup($group_guid);
    // Set the group properties that we can!
    $group->name = $name;
    $group->context_id = $context_id;
    // This is a unique identifier from the consumer for this context
    $group->consumer_key = $consumer_key;
    // Which consumer is creating this group
    $group->membership = ACCESS_PRIVATE;
    $group->access_id = ACCESS_PUBLIC;
    $group->briefdescription = elgg_echo('LTI:provision:group');
    $consumer_instance = new LTI_Tool_Consumer_Instance($group->consumer_key, elgg_get_config('dbprefix'));
    $context = new LTI_Context($consumer_instance, $group->context_id);
    $group->description = $context->title;
    $group->save();
    $group->join($user);
    // Add images
    $prefix = 'groups/' . $group->guid;
    $filename = GetImage($consumer_key, '.jpg');
    $thumbtiny = get_resized_image_from_existing_file($filename, 25, 25, true);
    $thumbsmall = get_resized_image_from_existing_file($filename, 40, 40, true);
    $thumbmedium = get_resized_image_from_existing_file($filename, 100, 100, true);
    $thumblarge = get_resized_image_from_existing_file($filename, 200, 200, false);
    if ($thumbtiny) {
        $thumb = new ElggFile();
        $thumb->owner_guid = $group->owner_guid;
        $thumb->setMimeType('image/jpeg');
        $thumb->setFilename($prefix . "tiny.jpg");
        $thumb->open("write");
        $thumb->write($thumbtiny);
        $thumb->close();
        $thumb->setFilename($prefix . "small.jpg");
        $thumb->open("write");
        $thumb->write($thumbsmall);
        $thumb->close();
        $thumb->setFilename($prefix . "medium.jpg");
        $thumb->open("write");
        $thumb->write($thumbmedium);
        $thumb->close();
        $thumb->setFilename($prefix . "large.jpg");
        $thumb->open("write");
        $thumb->write($thumblarge);
        $thumb->close();
        $group->icontime = time();
    }
    // return the URL
    return $group;
}
开发者ID:vsheokeen,项目名称:Elgg-Plugins,代码行数:50,代码来源:LTIGroup.php


示例7: put

 function put($url = '', $handle = null, $data = array())
 {
     if (!$url) {
         return false;
     }
     $hash = md5($url);
     $site = elgg_get_site_entity();
     if (!$handle) {
         $handle = $site->guid;
     }
     if (!empty($data)) {
         $thumbnails = !empty($data['thumbnails']) ? $data['thumbnails'] : array();
         $icons = !empty($data['icons']) ? $data['icons'] : array();
         $thumbnails = array_merge($thumbnails, $icons);
         if (!empty($thumbnails) && $this->config->get('cache_thumbnails')) {
             foreach ($thumbnails as $thumbnail_url) {
                 $imagesize = getimagesize($thumbnail_url);
                 if (empty($imagesize) || $imagesize[0] < $this->config->get('cache_thumb_size_lower_threshold')) {
                     continue;
                 }
                 $post_max_size = elgg_get_ini_setting_in_bytes('post_max_size');
                 $upload_max_filesize = elgg_get_ini_setting_in_bytes('upload_max_filesize');
                 $max_upload = $upload_max_filesize > $post_max_size ? $post_max_size : $upload_max_filesize;
                 $filesize = filesize($thumbnail_url);
                 if (!$filesize || $filesize > $max_upload) {
                     continue;
                 }
                 $size = $this->config->get('cache_thumb_size');
                 $thumb = get_resized_image_from_existing_file($thumbnail_url, $size, $size, false, 0, 0, 0, 0, true);
                 if ($thumb) {
                     $file = new ElggFile();
                     $file->owner_guid = $site->guid;
                     $file->setFilename("scraper_cache/thumbs/{$hash}.{$handle}.jpg");
                     $file->open('write');
                     $file->write($thumb);
                     $file->close();
                     $data['thumb_cache'] = time();
                     break;
                 }
             }
         }
     }
     $file = new ElggFile();
     $file->owner_guid = $site->guid;
     $file->setFilename("scraper_cache/resources/{$hash}.{$handle}.json");
     $file->open('write');
     $file->write(json_encode($data));
     $file->close();
     return $data;
 }
开发者ID:justangel,项目名称:hypeScraper,代码行数:50,代码来源:Cache.php


示例8: get_resized_image_from_uploaded_file

/**
 * Gets the jpeg contents of the resized version of an uploaded image
 * (Returns false if the uploaded file was not an image)
 *
 * @param string $input_name The name of the file input field on the submission form
 * @param int    $maxwidth   The maximum width of the resized image
 * @param int    $maxheight  The maximum height of the resized image
 * @param bool   $square     If set to true, will take the smallest
 *                           of maxwidth and maxheight and use it to set the
 *                           dimensions on all size; the image will be cropped.
 * @param bool   $upscale    Resize images smaller than $maxwidth x $maxheight?
 *
 * @return false|mixed The contents of the resized image, or false on failure
 */
function get_resized_image_from_uploaded_file($input_name, $maxwidth, $maxheight, $square = false, $upscale = false)
{
    $files = _elgg_services()->request->files;
    if (!$files->has($input_name)) {
        return false;
    }
    $file = $files->get($input_name);
    if (empty($file)) {
        // a file input was provided but no file uploaded
        return false;
    }
    if ($file->getError() !== 0) {
        return false;
    }
    return get_resized_image_from_existing_file($file->getPathname(), $maxwidth, $maxheight, $square, 0, 0, 0, 0, $upscale);
}
开发者ID:nirajkaushal,项目名称:Elgg,代码行数:30,代码来源:filestore.php


示例9: uploadCK

function uploadCK($page, $identifier, $obj)
{
    $funcNum2 = get_Input('CKEditorFuncNum', 'CKEditorFuncNum');
    $file = new ElggFile();
    $filestorename = strtolower(time() . $_FILES['upload']['name']);
    $file->setFilename($filestorename);
    $file->setMimeType($_FILES['upload']['type']);
    $file->owner_guid = elgg_get_logged_in_user_guid();
    $file->subtype = "file";
    $file->originalfilename = $filestorename;
    $file->access_id = ACCESS_PUBLIC;
    $file->open("write");
    $file->write(get_uploaded_file('upload'));
    $file->close();
    $result = $file->save();
    if ($result) {
        $master = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 550, 550);
        if ($master !== false) {
            $_SESSION['UPLOAD_DATA']['file_save'] = "started";
            $filehandler = new ElggFile();
            $filehandler->setFilename($filestorename);
            $filehandler->setMimeType($_FILES['upload']['type']);
            $filehandler->owner_guid = $user->guid;
            $filehandler->subtype = "file";
            $filehandler->originalfilename = $filestorename;
            $filehandler->access_id = ACCESS_PUBLIC;
            $filehandler->open("write");
            $filehandler->write($master);
            $filehandler->close();
            $filehandler->save();
            // Dev URL
            $url = elgg_get_site_url() . 'CKEditorView?file_guid=' . $filehandler->guid;
            //Production URL
            //$url ='/CKEditorView?file_guid='.$filehandler->guid;
            echo '<script type="text/javascript">
		window.parent.CKEDITOR.tools.callFunction(' . $funcNum2 . ', "' . $url . '","");
		</script>';
            exit;
        } else {
            echo '<script type="text/javascript">
		window.parent.CKEDITOR.tools.callFunction(' . $funcNum2 . ', "","");
		</script>';
            exit;
        }
    }
    return true;
}
开发者ID:socialweb,项目名称:PiGo,代码行数:47,代码来源:start.php


示例10: saveThumbnail

 protected function saveThumbnail($image, $name)
 {
     try {
         $thumbnail = get_resized_image_from_existing_file($image->getFilenameOnFilestore(), 60, 60, true);
     } catch (Exception $e) {
         return FALSE;
     }
     $thumb = new ElggFile();
     $thumb->setMimeType('image/jpeg');
     $thumb->access_id = $this->access_id;
     $thumb->setFilename($name);
     $thumb->open("write");
     $thumb->write($thumbnail);
     $thumb->save();
     $image->thumbnail_guid = $thumb->getGUID();
     if (!$thumb->getGUID()) {
         $thumb->delete();
         return FALSE;
     }
     return TRUE;
 }
开发者ID:nohup,项目名称:community_plugins,代码行数:21,代码来源:PluginProject.php


示例11: register_error

$return_value = $this->processFile($upload_video);
if (!file_exists($return_value->videofile)) {
    register_error(elgg_echo('izap_videos:error:notUploaded'));
    forward($_SERVER['HTTP_REFERER']);
    exit;
}
$this->access_id = 0;
$this->videotype = $return_value->videotype;
if ($return_value->videofile) {
    $this->videofile = $return_value->videofile;
}
if (empty($_FILES['upload_thumbnail']['name'])) {
    if ($return_value->thumb) {
        $this->orignal_thumb = $return_value->orignal_thumb;
        $this->imagesrc = $return_value->thumb;
    }
} else {
    if ($_FILES['upload_thumbnail']['error'] == 0) {
        $set_original_thumbnail = $this->getTmpPath('original_' . $_FILES['upload_thumbnail']['name']);
        $this->setFilename($set_original_thumbnail);
        $this->open("write");
        $this->write(file_get_contents($_FILES['upload_thumbnail']['tmp_name']));
        //set thumbnail size
        $thumbnail = get_resized_image_from_existing_file($this->getFilenameOnFilestore(), 650, 500);
        $set_thumb = $this->getTmpPath($_FILES['upload_thumbnail']['name']);
        $this->setFilename($set_thumb);
        $this->open("write");
        $this->write($thumbnail);
        $this->imagesrc = $set_thumb;
    }
}
开发者ID:justangel,项目名称:izap-videos,代码行数:31,代码来源:onserver.php


示例12: unset

            $thumb->open("write");
            $thumb->write($thumbnail);
            $thumb->close();
            $file->thumbnail = $prefix . "thumb" . $filestorename;
            unset($thumbnail);
        }
        $thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 153, 153, true);
        if ($thumbsmall) {
            $thumb->setFilename($prefix . "smallthumb" . $filestorename);
            $thumb->open("write");
            $thumb->write($thumbsmall);
            $thumb->close();
            $file->smallthumb = $prefix . "smallthumb" . $filestorename;
            unset($thumbsmall);
        }
        $thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 600, 600, false);
        if ($thumblarge) {
            $thumb->setFilename($prefix . "largethumb" . $filestorename);
            $thumb->open("write");
            $thumb->write($thumblarge);
            $thumb->close();
            $file->largethumb = $prefix . "largethumb" . $filestorename;
            unset($thumblarge);
        }
    }
}
// make sure session cache is cleared
unset($_SESSION['uploadtitle']);
unset($_SESSION['uploaddesc']);
unset($_SESSION['uploadtags']);
unset($_SESSION['uploadaccessid']);
开发者ID:ashwiniravi,项目名称:Elgg-Social-Network-Single-Sign-on-and-Web-Statistics,代码行数:31,代码来源:upload.php


示例13: facebook_connect_update_user_avatar

/**
 * Used to Pull in the latest avatar from facebook.
 *
 * @access public
 * @param array $user
 * @param string $file_location
 * @return void
 */
function facebook_connect_update_user_avatar($user, $file_location)
{
    $path = elgg_get_data_path();
    $tempfile = $path . $user->getGUID() . 'img.jpg';
    $imgContent = file_get_contents($file_location);
    $fp = fopen($tempfile, "w");
    fwrite($fp, $imgContent);
    fclose($fp);
    $sizes = array('topbar' => array(16, 16, TRUE), 'tiny' => array(25, 25, TRUE), 'small' => array(40, 40, TRUE), 'medium' => array(100, 100, TRUE), 'large' => array(200, 200, FALSE), 'master' => array(550, 550, FALSE));
    $filehandler = new ElggFile();
    $filehandler->owner_guid = $user->getGUID();
    foreach ($sizes as $size => $dimensions) {
        $image = get_resized_image_from_existing_file($tempfile, $dimensions[0], $dimensions[1], $dimensions[2]);
        $filehandler->setFilename("profile/{$user->guid}{$size}.jpg");
        $filehandler->open('write');
        $filehandler->write($image);
        $filehandler->close();
    }
    // update user's icontime
    $user->icontime = time();
    return TRUE;
}
开发者ID:rohit1290,项目名称:Facebook-Login-1.9-1.12,代码行数:30,代码来源:facebook_connect.php


示例14: implode

     $metadata['location'] = implode(', ', $location);
 }
 // we have received a verified email from a provider
 if ($verified) {
     elgg_set_user_validation_status($new_user->guid, true, 'hybridauth');
 }
 foreach ($metadata as $md_name => $md_value) {
     create_metadata($new_user->guid, $md_name, $md_value, '', $new_user->guid, ACCESS_PRIVATE, true);
 }
 if ($photo_url) {
     $icon_sizes = elgg_get_config('icon_sizes');
     $filehandler = new ElggFile();
     $filehandler->owner_guid = $new_user->guid;
     foreach ($icon_sizes as $size => $dimensions) {
         $image = get_resized_image_from_existing_file($photo_url, $dimensions[0], $dimensions[1], $dimensions[2]);
         $image = get_resized_image_from_existing_file($photo_url, $dimensions['w'], $dimensions['h'], $dimensions['square'], 0, 0, 0, 0, $dimensions['upscale']);
         $filehandler->setFilename("profile/{$new_user->guid}{$size}.jpg");
         $filehandler->open('write');
         $filehandler->write($image);
         $filehandler->close();
     }
     $new_user->icontime = time();
 }
 if ($provider && $provider_uid) {
     elgg_set_plugin_user_setting("{$provider}:uid", $provider_uid, $new_user->guid, 'elgg_hybridauth');
     elgg_trigger_plugin_hook('hybridauth:authenticate', $provider, array('entity' => $new_user));
 }
 $params = array_merge($params, $metadata);
 // @todo should registration be allowed no matter what the plugins return?
 if (!elgg_trigger_plugin_hook('register', 'user', $params, TRUE)) {
     $ia = elgg_set_ignore_access(true);
开发者ID:n8b,项目名称:VMN,代码行数:31,代码来源:register.php


示例15: processFile

 /**
  * Used to process the video file
  * @param string $file upload file name
  * @return object
  */
 protected function processFile($file)
 {
     $returnValue = new stdClass();
     $returnValue->type = 'uploaded';
     $fileName = $_FILES[$file['mainArray']]['name'][$file['fileName']];
     $error = $_FILES[$file['mainArray']]['error'][$file['fileName']];
     $tmpName = $_FILES[$file['mainArray']]['tmp_name'][$file['fileName']];
     $type = $_FILES[$file['mainArray']]['type'][$file['fileName']];
     $size = $_FILES[$file['mainArray']]['size'][$file['fileName']];
     // if error
     if ($error > 0) {
         return 104;
     }
     // if file is of zero size
     if ($size == 0) {
         return 105;
     }
     // check supported video type
     if (!izapSupportedVideos_izap_videos($fileName)) {
         return 106;
     }
     // check supported video size
     if (!izapCheckFileSize_izap_videos($size)) {
         return 107;
     }
     // upload the tmp file
     $newFileName = izapGetFriendlyFileName_izap_videos($fileName);
     $this->setFilename('tmp/' . $newFileName);
     $this->open("write");
     $this->write(file_get_contents($tmpName));
     $returnValue->tmpFile = $this->getFilenameOnFilestore();
     // take snapshot of the video
     $image = new izapConvert($returnValue->tmpFile);
     if ($image->photo()) {
         $retValues = $image->getValues(true);
         if ($retValues['imagename'] != '' && $retValues['imagecontent'] != '') {
             $this->setFilename('izap_videos/uploaded/' . $retValues['imagename']);
             $this->open("write");
             if ($this->write($retValues['imagecontent'])) {
                 $orignal_file_path = $this->getFilenameOnFilestore();
                 $thumb = get_resized_image_from_existing_file($orignal_file_path, 120, 90);
                 $this->setFilename('izap_videos/uploaded/' . $retValues['imagename']);
                 $this->open("write");
                 $this->write($thumb);
                 $this->close();
                 $returnValue->thumb = 'izap_videos/uploaded/' . $retValues['imagename'];
                 // Defining new preview attribute of standard object
                 $returnValue->preview_400 = 'izap_videos/uploaded/preview_400';
                 $returnValue->preview_200 = 'izap_videos/uploaded/preview_200';
             }
         }
     }
     // check if it is flv, then dont send it to queue
     if (izap_get_file_extension($returnValue->tmpFile) == 'flv') {
         $file_name = 'izap_videos/uploaded/' . $newFileName;
         $this->setFilename($file_name);
         $this->open("write");
         $this->write(file_get_contents($returnValue->tmpFile));
         $this->converted = 'yes';
         $this->videofile = $file_name;
         $this->orignalfile = $file_name;
         $returnValue->is_flv = 'yes';
         // remove the tmp file
         @unlink($returnValue->tmpFile);
     }
     return $returnValue;
 }
开发者ID:iionly,项目名称:izap_videos,代码行数:72,代码来源:izap_videos.php


示例16: elgg_create_media_thumbnails

/**
 * Creates entity media thumbnails
 *
 * @param mixed       $file        Path to file, or an array with 'tmp_name' and 'name', or ElggFile
 * @param \ElggEntity $entity      Entity
 * @param string      $type        Media type
 * @param array       $crop_coords Cropping coordinates
 * @return \ElggFile[]|false
 */
function elgg_create_media_thumbnails($file, \ElggEntity $entity, $type = 'icon', $crop_coords = [])
{
    if ($file instanceof ElggFile) {
        $path = $file->getFilenameOnFilestore();
    } else {
        if (is_array($file)) {
            $path = elgg_extract('tmp_name', (array) $file);
        } else {
            $path = (string) $file;
        }
    }
    if (!file_exists($path)) {
        return false;
    }
    $thumb_sizes = elgg_media_get_thumb_sizes($entity, $type);
    $master_info = $thumb_sizes['master'];
    unset($thumb_sizes['master']);
    // master is used as base for cropping
    $filehandler = elgg_get_media_original($entity, $type);
    if (!$filehandler) {
        return false;
    }
    $resized = get_resized_image_from_existing_file($path, $master_info['w'], $master_info['h'], $master_info['square'], 0, 0, 0, 0, $master_info['upscale']);
    if (!$resized) {
        return false;
    }
    $master = new ElggFile();
    $master->owner_guid = $entity->guid;
    $master->setFilename("media/{$type}/master.jpg");
    $master->open('write');
    $master->write($resized);
    $master->close();
    $thumbs = [];
    $x1 = (int) elgg_extract('x1', $crop_coords);
    $y1 = (int) elgg_extract('y1', $crop_coords);
    $x2 = (int) elgg_extract('x2', $crop_coords);
    $y2 = (int) elgg_extract('y2', $crop_coords);
    foreach ($thumb_sizes as $name => $size_info) {
        $resized = get_resized_image_from_existing_file($path, $size_info['w'], $size_info['h'], $size_info['square'], $x1, $y1, $x2, $y2, $size_info['upscale']);
        if (!$resized) {
            foreach ($thumbs as $thumb) {
                $thumb->delete();
            }
            return false;
        }
        $thumb = new ElggFile();
        $thumb->owner_guid = $entity->guid;
        $thumb->setFilename("media/{$type}/{$name}.jpg");
        $thumb->open('write');
        $thumb->write($resized);
        $thumb->close();
        $thumbs[] = $thumb;
    }
    //$entity->{"{$type}time"} = time();
    $entity->{"{$type}_time_created"} = time();
    // normalize coords to master
    $natural_image_size = getimagesize($path);
    $master_image_size = getimagesize($master->getFilenameOnFilestore());
    $ratio = $master_image_size[0] / $natural_image_size[0];
    $entity->{"{$type}_x1"} = $x1 * $ratio;
    $entity->{"{$type}_x2"} = $x2 * $ratio;
    $entity->{"{$type}_y1"} = $y1 * $ratio;
    $entity->{"{$type}_y2"} = $y2 * $ratio;
    return $thumbs;
}
开发者ID:hypeJunction,项目名称:elgg_media,代码行数:74,代码来源:functions.php


示例17: video_create_thumbnails

/**
 * Make thumbnails of given video position. Defaults to beginning of video.
 *
 * @param Video $video    The video object
 * @param int   $position Video position
 */
function video_create_thumbnails($video, $position = 0)
{
    $icon_sizes = elgg_get_config('icon_sizes');
    $square = elgg_get_plugin_setting('square_icons', 'video');
    // Default to square thumbnail images
    if (is_null($square)) {
        $square = true;
    }
    $square = $square == 1 ? true : false;
    $dir = $video->getFileDirectory();
    $guid = $video->getGUID();
    // Use default thumbnail as master
    $imagepath = "{$dir}/icon-master.jpg";
    try {
        $thumbnailer = new VideoThumbnailer();
        $thumbnailer->setInputFile($video->getFilenameOnFilestore());
        $thumbnailer->setOutputFile($imagepath);
        $thumbnailer->setPosition($position);
        $thumbnailer->execute();
    } catch (exception $e) {
        $msg = elgg_echo('VideoException:ThumbnailCreationFailed', array($video->getFilenameOnFilestore(), $e->getMessage(), $thumbnailer->getCommand()));
        error_log($msg);
        elgg_add_admin_notice('video_thumbnailing_error', $msg);
        return false;
    }
    $files = array();
    // Create the thumbnails
    foreach ($icon_sizes as $name => $size_info) {
        // We have already created master image
        if ($name == 'master') {
            continue;
        }
        $resized = get_resized_image_from_existing_file($imagepath, $size_info['w'], $size_info['h'], $square);
        if ($resized) {
            $file = new ElggFile();
            $file->owner_guid = $video->owner_guid;
            $file->container_guid = $guid;
            $file->setFilename("video/{$guid}/icon-{$name}.jpg");
            $file->open('write');
            $file->write($resized);
            $file->close();
            $files[] = $file;
        } else {
            error_log("ERROR: Failed to create thumbnail '{$name}' for video {$video->getFilenameOnFilestore()}.");
            // Delete all images if one fails
            foreach ($files as $file) {
                $file->delete();
            }
            return false;
        }
    }
    $video->icontime = time();
    return true;
}
开发者ID:juho-jaakkola,项目名称:elgg-videos,代码行数:60,代码来源:video.php


示例18: create_file

function create_file($container_guid, $title, $desc, $access_id, $guid, $tags, $new_file)
{
    // register_error("Creating file: " . $container_guid . ", vars: " . print_r(array($title, $desc, $access_id, $guid, $tags, $new_file), true));
    if ($new_file) {
        // must have a file if a new file upload
        if (empty($_FILES['upload']['name'])) {
            // cache information in session
            $_SESSION['uploadtitle'] = $title;
            $_SESSION['uploaddesc'] = $desc;
            $_SESSION['uploadtags'] = $tags;
            $_SESSION['uploadaccessid'] = $access_id;
            register_error(elgg_echo('file:nofile') . "no file new");
            forward($_SERVER['HTTP_REFERER']);
        }
        $file = new FilePluginFile();
        $file->subtype = "file";
        // if no title on new upload, grab filename
        if (empty($title)) {
            $title = $_FILES['upload']['name'];
        }
    } else {
        // load original file object
        $file = get_entity($guid);
        if (!$file) {
            register_error(elgg_echo('file:cannotload') . 'can"t load existing');
            forward($_SERVER['HTTP_REFERER']);
        }
        // user must be able to edit file
        if (!$file->canEdit()) {
            register_error(elgg_echo('file:noaccess') . 'no access to existing');
            forward($_SERVER['HTTP_REFERER']);
        }
    }
    $file->title = $title;
    $file->description = $desc;
    $file->access_id = $access_id;
    $file->container_guid = $container_guid;
    $tags = explode(",", $tags);
    $file->tags = $tags;
    // we have a file upload, so process it
    if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) {
        $prefix = "file/";
        // if previous file, delete it
        if ($new_file == false) {
            $filename = $file->getFilenameOnFilestore();
            if (file_exists($filename)) {
                unlink($filename);
            }
            // use same filename on the disk - ensures thumbnails are overwritten
            $filestorename = $file->getFilename();
            $filestorename = elgg_substr($filestorename, elgg_strlen($prefix));
        } else {
            $filestorename = elgg_strtolower(time() . $_FILES['upload']['name']);
        }
        $file->setFilename($prefix . $filestorename);
        $file->setMimeType($_FILES['upload']['type']);
        $file->originalfilename = $_FILES['upload']['name'];
        $file->simpletype = get_general_file_type($_FILES['upload']['type']);
        $file->open("write");
        $file->write(get_uploaded_file('upload'));
        $file->close();
        $guid = $file->save();
        // if image, we need to create thumbnails (this should be moved into a function)
        if ($guid && $file->simpletype == "image") {
            $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 60, 60, true);
            if ($thumbnail) {
                $thumb = new ElggFile();
                $thumb->setMimeType($_FILES['upload']['type']);
                $thumb->setFilename($prefix . "thumb" . $filestorename);
                $thumb->open("write");
                $thumb->write($thumbnail);
                $thumb->close();
                $file->thumbnail = $prefix . "thumb" . $filestorename;
                unset($thumbnail);
            }
            $thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 153, 153, true);
            if ($thumbsmall) {
                $thumb->setFilename($prefix . "smallthumb" . $filestorename);
                $thumb->open("write");
                $thumb->write($thumbsmall);
                $thumb->close();
                $file->smallthumb = $prefix . "smallthumb" . $filestorename;
                unset($thumbsmall);
            }
            $thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 600, 600, false);
            if ($thumblarge) {
                $thumb->setFilename($prefix . "largethumb" . $filestorename);
                $thumb->open("write");
                $thumb->write($thumblarge);
                $thumb->close();
                $file->largethumb = $prefix . "largethumb" . $filestorename;
                unset($thumblarge);
            }
        }
    } else {
        // not saving a file but still need to save the entity to push attributes to database
        $file->save();
    }
    return array($file, $guid);
}
开发者ID:psndcsrv,项目名称:file_multigroup_upload,代码行数:100,代码来源:upload.php


示例19: ElggFile

if (empty($icontime)) {
    return;
}
$user_guid = $user->getGUID();
$filehandler = new ElggFile();
$filehandler->owner_guid = $user_guid;
$filehandler->setFilename("profile/{$user_guid}master.jpg");
if ($filehandler->exists()) {
    $image_data = $filehandler->grabFile();
}
if (empty($image_data)) {
    return;
}
$x1 = $user->x1;
$x2 = $user->x2;
$y1 = $user->y1;
$y2 = $user->y2;
if ($x1 === null) {
    return $image_data;
}
// apply user cropping config
// create temp file for resizing
$tmpfname = tempnam(elgg_get_data_path(), 'elgg_avatar_service');
$handle = fopen($tmpfname, 'w');
fwrite($handle, $image_data);
fclose($handle);
// apply resizing
$result = get_resized_image_from_existing_file($tmpfname, 2048, 2048, true, $x1, $y1, $x2, $y2, false);
// remove temp file
unlink($tmpfname);
echo $result;
开发者ID:coldtrick,项目名称:avatar_service,代码行数:31,代码来源:profile.php


示例20: theme_haarlem_intranet_profile_sync_profile_icon

/**
 * Update the user profile icon based on profile_sync data
 *
 * @param string $event  the name of the event
 * @param string $type   the type of the event
 * @param mixed  $object supplied object
 *
 * @return void
 */
function theme_haarlem_intranet_profile_sync_profile_icon($event, $type, $object)
{
    if (empty($object) || !is_array($object)) {
        return;
    }
    $user = elgg_extract('entity', $object);
    if (empty($user) || !elgg_instanceof($user, 'user')) {
        return;
    }
    // handle icons
    $datasource = elgg_extract('datasource', $object);
    $source_row = elgg_extract('source_row', $object);
    if (empty($datasource) || empty($source_row)) {
        return;
    }
    // handle custom icon
    $fh = new ElggFile();
    $fh->owner_guid = $user->getGUID();
    $icon_sizes = elgg_get_config('icon_sizes');
    $icon_path = elgg_extract('profielfoto', $source_row);
    $icon_path = profile_sync_filter_var($icon_path);
    if (empty($icon_path)) {
        // remove icon
        foreach ($icon_sizes as $size => $info) {
            $fh->setFilename("haarlem_icon/{$size}.jpg");
            if ($fh->exists()) {
                $fh->delete();
            }
        }
        unset($user->haarlem_icontime);
        return;
    }
    $csv_location = $datasource->csv_location;
    if (empty($csv_location)) {
        return;
    }
    $csv_filename = basename($csv_location);
    $base_location = rtrim(str_ireplace($csv_filename, "", $csv_location), DIRECTORY_SEPARATOR);
    $icon_path = sanitise_filepath($icon_path, false);
    // prevent abuse (like ../../......)
    $icon_path = ltrim($icon_path, DIRECTORY_SEPARATOR);
    // remove beginning /
    $ 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP get_resized_image_from_uploaded_file函数代码示例发布时间:2022-05-15
下一篇:
PHP get_required_files函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap