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


PHP wp_create_thumbnail函数代码示例

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


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

示例1: body

 #parse message body (not really used yet, will be used for multiple attachments)
 $attach = parse($struct);
 $attach_parts = get_attachments($attach);
 #get the attachment
 $attachment = imap_fetchbody($mbox, $iCount, 2);
 if ($attachment != '') {
     $attachment = imap_base64($attachment);
     $temp_file = mb_convert_encoding(mb_decode_mimeheader($struct->parts[1]->dparameters[0]->value), $blog_charset, "auto");
     echo $temp_file;
     if (!($temp_fp = fopen("attach/" . $temp_file, "w"))) {
         echo "error1";
         continue;
     }
     fputs($temp_fp, $attachment);
     fclose($temp_fp);
     wp_create_thumbnail("attach/" . $temp_file, 160, "");
 } else {
     $attachment = false;
 }
 if ($xooptDB) {
     $sql = "SELECT ID, user_level FROM {$tableusers} WHERE user_login='{$user_login}' ORDER BY ID DESC LIMIT 1";
     $result = $wpdb->get_row($sql);
     if (!$result) {
         echo '<p><b>Wrong login</b></p></div>';
         continue;
     } else {
         $sql = "SELECT * FROM " . $xoopsDB->prefix('users') . " WHERE uname='" . trim($user_login) . "' AND pass='" . md5(trim($user_pass)) . "' ORDER BY uid DESC LIMIT 1";
         $result1 = $wpdb->get_row($sql);
         if (!$result1) {
             echo '<p><b>Wrong password.</b></p></div>';
             continue;
开发者ID:BackupTheBerlios,项目名称:nobunobuxoops-svn,代码行数:31,代码来源:wp-moblog.php

示例2: chmod

            } else {
                chmod($pathtofile, 0666);
                @unlink($img1);
            }
        } else {
            rename($img1, $pathtofile) or die(sprintf(__("Couldn't upload your file to %s."), $pathtofile));
        }
        if ($_POST['thumbsize'] != 'none') {
            if ($_POST['thumbsize'] == 'small') {
                $max_side = 200;
            } elseif ($_POST['thumbsize'] == 'large') {
                $max_side = 400;
            } elseif ($_POST['thumbsize'] == 'custom') {
                $max_side = intval($_POST['imgthumbsizecustom']);
            }
            $result = wp_create_thumbnail($pathtofile, $max_side, NULL);
            if ($result != 1) {
                print $result;
            }
        }
        if (ereg('image/', $img1_type)) {
            $piece_of_code = "<img src='" . get_settings('fileupload_url') . "/{$img1_name}' alt='{$imgdesc}' />";
        } else {
            $piece_of_code = "<a href='" . get_settings('fileupload_url') . "/{$img1_name}' title='{$imgdesc}'>{$imgdesc}</a>";
        }
        $piece_of_code = htmlspecialchars($piece_of_code);
        ?>

<h3><?php 
        _e('File uploaded!');
        ?>
开发者ID:johnwonder,项目名称:WordPressLearn,代码行数:31,代码来源:upload.php

示例3: bp_core_resize_avatar

function bp_core_resize_avatar($file, $size = false)
{
    if (!$size) {
        $size = CORE_CROPPING_CANVAS_MAX;
    }
    $canvas = wp_create_thumbnail($file, $size);
    if ($canvas->errors) {
        return false;
    }
    return $canvas = str_replace('//', '/', $canvas);
}
开发者ID:alvaropereyra,项目名称:shrekcms,代码行数:11,代码来源:bp-core-avatars.php

示例4: wp_getattach

function wp_getattach($content, $prefix = "", $create_thumbs = 0)
{
    $contents = explode("\r\n\r\n", $content);
    $subtype = preg_match("/Content-Type: [^\\/]*\\/([^\\;]*);/", $contents[0], $matches);
    if ($subtype) {
        $subtype = strtolower($matches[1]);
    }
    $temp_file = "";
    if (in_array($subtype, array("gif", "jpg", "jpeg", "png"))) {
        if ($prefix == 0 && eregi("name=\"?([^\"\n]+)\"?", $contents[0], $filereg)) {
            $filename = ereg_replace("[\t\r\n]", "", $filereg[1]);
            if (function_exists('mb_convert_encoding')) {
                $temp_file = mb_convert_encoding(mb_decode_mimeheader($filename, $blog_charset, "auto"));
            } else {
                $temp_file = $filename;
            }
        }
        // 添付データをデコードして保存
        if (eregi("Content-Transfer-Encoding:.*base64", $contents[0])) {
            $tmp = base64_decode($contents[1]);
            if (!$temp_file) {
                $temp_file_base = $prefix . "_" . time();
            } else {
                $temp_file_info = pathinfo($temp_file);
                $temp_file_base = basename($temp_file, "." . $temp_file_info["extension"]);
            }
            $i = 0;
            $temp_file = $temp_file_base . ".{$subtype}";
            while (file_exists("attach/" . $temp_file)) {
                $temp_file = $temp_file_base . "-" . $i . ".{$subtype}";
                $i++;
            }
            if (!($temp_fp = fopen("attach/" . $temp_file, "wb"))) {
                echo "Error1<br/>\n";
                continue;
            }
            fputs($temp_fp, $tmp);
            fclose($temp_fp);
            if ($create_thumbs) {
                wp_create_thumbnail("attach/" . $temp_file, 180, "");
            }
        }
        echo "{$temp_file} <br/>\n";
        return $temp_file;
    }
    return false;
}
开发者ID:BackupTheBerlios,项目名称:nobunobuxoops-svn,代码行数:47,代码来源:wp-mail.php

示例5: wp_generate_attachment_metadata

function wp_generate_attachment_metadata( $attachment_id, $file ) {
	$attachment = get_post( $attachment_id );

	$metadata = array();
	if ( preg_match('!^image/!', get_post_mime_type( $attachment )) ) {
		$imagesize = getimagesize($file);
		$metadata['width'] = $imagesize['0'];
		$metadata['height'] = $imagesize['1'];
		list($uwidth, $uheight) = get_udims($metadata['width'], $metadata['height']);
		$metadata['hwstring_small'] = "height='$uheight' width='$uwidth'";
		$metadata['file'] = $file;

		$max = apply_filters( 'wp_thumbnail_creation_size_limit', 3 * 1024 * 1024, $attachment_id, $file );

		if ( $max < 0 || $metadata['width'] * $metadata['height'] < $max ) {
			$max_side = apply_filters( 'wp_thumbnail_max_side_length', 128, $attachment_id, $file );
			$thumb = wp_create_thumbnail( $file, $max_side );

			if ( @file_exists($thumb) )
				$metadata['thumb'] = basename($thumb);
		}
	}
	return apply_filters( 'wp_generate_attachment_metadata', $metadata );
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:24,代码来源:admin-functions.php

示例6: bp_core_avatar_handle_upload

function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) {
	global $bp;

	/***
	 * You may want to hook into this filter if you want to override this function.
	 * Make sure you return false.
	 */
	if ( !apply_filters( 'bp_core_pre_avatar_handle_upload', true, $file, $upload_dir_filter ) )
		return true;

	require_once( ABSPATH . '/wp-admin/includes/image.php' );
	require_once( ABSPATH . '/wp-admin/includes/file.php' );

	$uploadErrors = array(
		0 => __("There is no error, the file uploaded with success", 'buddypress'),
		1 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE),
		2 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE),
		3 => __("The uploaded file was only partially uploaded", 'buddypress'),
		4 => __("No file was uploaded", 'buddypress'),
		6 => __("Missing a temporary folder", 'buddypress')
	);

	if ( !bp_core_check_avatar_upload( $file ) ) {
		bp_core_add_message( sprintf( __( 'Your upload failed, please try again. Error was: %s', 'buddypress' ), $uploadErrors[$file['file']['error']] ), 'error' );
		return false;
	}

	if ( !bp_core_check_avatar_size( $file ) ) {
		bp_core_add_message( sprintf( __( 'The file you uploaded is too big. Please upload a file under %s', 'buddypress'), size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE) ), 'error' );
		return false;
	}

	if ( !bp_core_check_avatar_type( $file ) ) {
		bp_core_add_message( __( 'Please upload only JPG, GIF or PNG photos.', 'buddypress' ), 'error' );
		return false;
	}

	/* Filter the upload location */
	add_filter( 'upload_dir', $upload_dir_filter, 10, 0 );

	$bp->avatar_admin->original = wp_handle_upload( $file['file'], array( 'action'=> 'bp_avatar_upload' ) );

	/* Move the file to the correct upload location. */
	if ( !empty( $bp->avatar_admin->original['error'] ) ) {
		bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $bp->avatar_admin->original['error'] ), 'error' );
		return false;
	}

	/* Get image size */
	$size = @getimagesize( $bp->avatar_admin->original['file'] );

	/* Check image size and shrink if too large */
	if ( $size[0] > BP_AVATAR_ORIGINAL_MAX_WIDTH ) {
		$thumb = wp_create_thumbnail( $bp->avatar_admin->original['file'], BP_AVATAR_ORIGINAL_MAX_WIDTH );

		/* Check for thumbnail creation errors */
		if ( is_wp_error( $thumb ) ) {
			bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $thumb->get_error_message() ), 'error' );
			return false;
		}

		/* Thumbnail is good so proceed */
		$bp->avatar_admin->resized = $thumb;
	}

	/* We only want to handle one image after resize. */
	if ( empty( $bp->avatar_admin->resized ) )
		$bp->avatar_admin->image->dir = str_replace( BP_AVATAR_UPLOAD_PATH, '', $bp->avatar_admin->original['file'] );
	else {
		$bp->avatar_admin->image->dir = str_replace( BP_AVATAR_UPLOAD_PATH, '', $bp->avatar_admin->resized );
		@unlink( $bp->avatar_admin->original['file'] );
	}

	/* Set the url value for the image */
	$bp->avatar_admin->image->url = BP_AVATAR_URL . $bp->avatar_admin->image->dir;

	return true;
}
开发者ID:n-sane,项目名称:zaroka,代码行数:78,代码来源:bp-core-avatars.php

示例7: wp_insert_attachment

     // Save the data
     $id = wp_insert_attachment($attachment, $file, $post);
     if (preg_match('!^image/!', $attachment['post_mime_type'])) {
         // Generate the attachment's postmeta.
         $imagesize = getimagesize($file);
         $imagedata['width'] = $imagesize['0'];
         $imagedata['height'] = $imagesize['1'];
         list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']);
         $imagedata['hwstring_small'] = "height='{$uheight}' width='{$uwidth}'";
         $imagedata['file'] = $file;
         add_post_meta($id, '_wp_attachment_metadata', $imagedata);
         if ($imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024) {
             if ($imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3) {
                 $thumb = wp_create_thumbnail($file, 128);
             } elseif ($imagedata['height'] > 96) {
                 $thumb = wp_create_thumbnail($file, 96);
             }
             if (@file_exists($thumb)) {
                 $newdata = $imagedata;
                 $newdata['thumb'] = basename($thumb);
                 update_post_meta($id, '_wp_attachment_metadata', $newdata, $imagedata);
             } else {
                 $error = $thumb;
             }
         }
     } else {
         add_post_meta($id, '_wp_attachment_metadata', array());
     }
     header("Location: " . basename(__FILE__) . "?post={$post}&all={$all}&action=view&start=0");
     die;
 case 'upload':
开发者ID:robertlange81,项目名称:Website,代码行数:31,代码来源:inline-uploading.php

示例8: set_fb_image_as_bp_avatar

 /**
  * Gets FB profile image and sets it as BuddyPress avatar.
  */
 function set_fb_image_as_bp_avatar($user_id, $me)
 {
     if (!defined('BP_VERSION')) {
         return true;
     }
     if (!function_exists('bp_core_avatar_upload_path')) {
         return true;
     }
     if (!$me || !@$me['id']) {
         return false;
     }
     $fb_uid = $me['id'];
     if (function_exists('xprofile_avatar_upload_dir')) {
         $xpath = xprofile_avatar_upload_dir(false, $user_id);
         $path = $xpath['path'];
     }
     if (!function_exists('xprofile_avatar_upload_dir') || empty($path)) {
         $object = 'user';
         $avatar_dir = apply_filters('bp_core_avatar_dir', 'avatars', $object);
         $path = bp_core_avatar_upload_path() . "/{$avatar_dir}/" . $user_id;
         $path = apply_filters('bp_core_avatar_folder_dir', $path, $user_id, $object, $avatar_dir);
         if (!realpath($path)) {
             @wp_mkdir_p($path);
         }
     }
     // Get FB picture
     //$fb_img = file_get_contents("http://graph.facebook.com/{$fb_uid}/picture?type=large");
     $page = wp_remote_get("http://graph.facebook.com/{$fb_uid}/picture?type=large", array('method' => 'GET', 'timeout' => '5', 'redirection' => '5', 'user-agent' => 'wdfb', 'blocking' => true, 'compress' => false, 'decompress' => true, 'sslverify' => false));
     if (is_wp_error($page)) {
         return false;
     }
     // Request fail
     if ((int) $page['response']['code'] != 200) {
         return false;
     }
     // Request fail
     $fb_img = $page['body'];
     $filename = md5($fb_uid);
     $filepath = "{$path}/{$filename}";
     file_put_contents($filepath, $fb_img);
     // Determine the right extension
     $info = getimagesize($filepath);
     $extension = false;
     if (function_exists('image_type_to_extension')) {
         $extension = image_type_to_extension($info[2], false);
     } else {
         switch ($info[2]) {
             case IMAGETYPE_GIF:
                 $extension = 'gif';
                 break;
             case IMAGETYPE_JPEG:
                 $extension = 'jpg';
                 break;
             case IMAGETYPE_PNG:
                 $extension = 'png';
                 break;
         }
     }
     // Unknown file type, clean up
     if (!$extension) {
         @unlink($filepath);
         return false;
     }
     $extension = 'jpeg' == strtolower($extension) ? 'jpg' : $extension;
     // Forcing .jpg extension for JPEGs
     // Clear old avatars
     $imgs = glob($path . '/*.{gif,png,jpg}', GLOB_BRACE);
     if (is_array($imgs)) {
         foreach ($imgs as $old) {
             @unlink($old);
         }
     }
     // Create and set new avatar
     if (defined('WDFB_BP_AVATAR_AUTO_CROP') && WDFB_BP_AVATAR_AUTO_CROP) {
         // Explicitly requested thumbnail processing
         // First, determine the centering position for cropping
         if ($info && isset($info[0]) && $info[0] && isset($info[1]) && $info[1]) {
             $full = apply_filters('wdfb-avatar-auto_crop', array('x' => (int) (($info[0] - bp_core_avatar_full_width()) / 2), 'y' => (int) (($info[1] - bp_core_avatar_full_height()) / 2), 'width' => bp_core_avatar_full_width(), 'height' => bp_core_avatar_full_height()), $filepath, $info);
         }
         $crop = $full ? wp_crop_image($filepath, $full['x'], $full['y'], $full['width'], $full['height'], bp_core_avatar_full_width(), bp_core_avatar_full_height(), false, "{$filepath}-bpfull.{$extension}") : false;
         if (!$crop) {
             @unlink($filepath);
             return false;
         }
         // Now, the thumbnail. First, try to resize the full avatar
         $thumb_file = wp_create_thumbnail("{$filepath}-bpfull.{$extension}", bp_core_avatar_thumb_width());
         if (!is_wp_error($thumb_file)) {
             // All good! We're done - clean up
             copy($thumb_file, "{$filepath}-bpthumb.{$extension}");
             @unlink($thumb_file);
         } else {
             // Sigh. Let's just fake it by using the original file then.
             copy("{$filepath}-bpfull.{$extension}", "{$filepath}-bpthumb.{$extension}");
         }
         @unlink($filepath);
         return true;
     } else {
//.........这里部分代码省略.........
开发者ID:m-godefroid76,项目名称:devrestofactory,代码行数:101,代码来源:class_wdfb_model.php

示例9: wp_getattach

function wp_getattach(&$content, $prefix = "", $create_thumbs = 0)
{
    $allowedtypes = explode(' ', trim(get_settings('fileupload_allowedtypes')));
    $allowedimage = array_intersect($allowedtypes, array('gig', 'jpg', 'jpeg', 'png'));
    $subtype = $content['subtype'];
    if (!empty($content['name'])) {
        $origname = $content['name'];
        if (function_exists('mb_convert_encoding')) {
            $origname = mb_conv(mb_decode_mimeheader($origname), $GLOBALS['blog_charset'], "auto");
        }
        $filename_info = pathinfo($origname);
        $subtype = $filename_info["extension"];
        //		$filename_base = basename($filename, "." . $filename_info["extension"]);
    }
    $filename_base = $prefix . "_" . time();
    if (in_array($subtype, $allowedtypes)) {
        if (!empty($content['encodings']) && $content['encodings'] == 'base64') {
            $tmp = base64_decode($content['body']);
            $i = 0;
            $filename = $filename_base . ".{$subtype}";
            while (file_exists(get_settings('fileupload_realpath') . '/' . $filename)) {
                $filename = $filename_base . "-" . $i . ".{$subtype}";
                $i++;
            }
            if (!($fp = fopen(get_settings('fileupload_realpath') . '/' . $filename, "wb"))) {
                echo "Error : Could not write attatched file.<br />\n";
                return false;
            }
            fputs($fp, $tmp);
            fclose($fp);
            if (in_array($subtype, $allowedimage)) {
                if ($create_thumbs) {
                    wp_create_thumbnail(get_settings('fileupload_realpath') . '/' . $filename, 180, "");
                }
            }
        }
        echo "{$filename} <br />\n";
        return array($filename, in_array($subtype, $allowedimage), $origname);
    }
    return false;
}
开发者ID:BackupTheBerlios,项目名称:nobunobuxoops-svn,代码行数:41,代码来源:wp-mail.php

示例10: bp_links_embed_download_avatar

function bp_links_embed_download_avatar($url)
{
    global $bp;
    require_once ABSPATH . '/wp-admin/includes/image.php';
    $bp->avatar_admin->original = bp_links_embed_upload_from_url($url);
    // Move the file to the correct upload location.
    if (!empty($bp->avatar_admin->original['error'])) {
        bp_core_add_message(sprintf('%1$s %2$s', __('Upload Failed! Error was:', 'buddypress-links'), $bp->avatar_admin->original['error']), 'error');
        return false;
    }
    // Resize the image down to something manageable and then delete the original
    if (getimagesize($bp->avatar_admin->original['file']) > BP_AVATAR_ORIGINAL_MAX_WIDTH) {
        $bp->avatar_admin->resized = wp_create_thumbnail($bp->avatar_admin->original['file'], BP_AVATAR_ORIGINAL_MAX_WIDTH);
    }
    $bp->avatar_admin->image = new stdClass();
    // We only want to handle one image after resize.
    if (empty($bp->avatar_admin->resized)) {
        $bp->avatar_admin->image->dir = $bp->avatar_admin->original['file'];
    } else {
        $bp->avatar_admin->image->dir = $bp->avatar_admin->resized;
        @unlink($bp->avatar_admin->original['file']);
    }
    /* Set the url value for the image */
    $bp->avatar_admin->image->url = str_replace(bp_core_avatar_upload_path(), bp_core_avatar_url(), $bp->avatar_admin->image->dir);
    return true;
}
开发者ID:adisonc,项目名称:MaineLearning,代码行数:26,代码来源:bp-links-embed.php

示例11: handle_upload

 function handle_upload($file, $upload_dir_filter)
 {
     /***
      * You may want to hook into this filter if you want to override this function.
      * Make sure you return false.
      */
     if (!apply_filters('pre_avatar_handle_upload', true, $file, $upload_dir_filter)) {
         return true;
     }
     require_once ABSPATH . '/wp-admin/includes/image.php';
     require_once ABSPATH . '/wp-admin/includes/file.php';
     $uploadErrors = array(0 => __("There is no error, the file uploaded with success", 'avatar'), 1 => __("Your image was bigger than the maximum allowed file size of: ", 'avatar') . size_format(AVATAR_ORIGINAL_MAX_FILESIZE), 2 => __("Your image was bigger than the maximum allowed file size of: ", 'avatar') . size_format(AVATAR_ORIGINAL_MAX_FILESIZE), 3 => __("The uploaded file was only partially uploaded", 'avatar'), 4 => __("No file was uploaded", 'avatar'), 6 => __("Missing a temporary folder", 'avatar'));
     if (!$this->check_avatar_upload($file)) {
         $this->notices[] = array('error', sprintf(__('Your upload failed, please try again. Error was: %s', 'avatar'), $uploadErrors[$file['error']]));
         return false;
     }
     if (!$this->check_avatar_size($file)) {
         $this->notices[] = array('error', sprintf(__('The file you uploaded is too big. Please upload a file under %s', 'avatar'), size_format(AVATAR_ORIGINAL_MAX_FILESIZE)));
         return false;
     }
     if (!$this->check_avatar_type($file)) {
         $this->notices[] = array('error', __('Please upload only JPG, GIF or PNG photos.', 'avatar'));
         return false;
     }
     /* Filter the upload location */
     add_filter('upload_dir', $upload_dir_filter, 10, 0);
     $upload = wp_handle_upload($file['file'], array('test_form' => true, 'action' => $_POST['action']));
     /* Move the file to the correct upload location. */
     if (!empty($upload['error'])) {
         $this->notices[] = array('error', sprintf(__('Upload Failed! Error was: %s', 'avatar'), $upload['error']));
         return false;
     }
     /* Get image size */
     $size = @getimagesize($upload['file']);
     /* Check image size and shrink if too large */
     if ($size[0] > AVATAR_ORIGINAL_MAX_WIDTH) {
         $thumb = wp_create_thumbnail($upload['file'], AVATAR_ORIGINAL_MAX_WIDTH);
         /* Check for thumbnail creation errors */
         if (is_wp_error($thumb)) {
             $this->notices[] = array('error', sprintf(__('Upload Failed! Error was: %s', 'avatar'), $thumb->get_error_message()));
             return false;
         }
         /* Thumbnail is good so proceed */
         $resized = $thumb;
     }
     /* We only want to handle one image after resize. */
     if (empty($resized)) {
         set_transient($this->dir_transient, str_replace($this->path, '', $upload['file']));
     } else {
         set_transient($this->dir_transient, str_replace($this->path, '', $resized));
         @unlink($upload['file']);
     }
     /* Set the url value for the image */
     set_transient($this->url_transient, $this->url . get_transient($this->dir_transient));
     return true;
 }
开发者ID:RalphBrabante,项目名称:sysgage,代码行数:56,代码来源:avatar.php


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