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

PHP image_resize_dimensions函数代码示例

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

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



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

示例1: file_processValue

function file_processValue($Value, $Type, $Field, $Config, $EID)
{
    if (!empty($Value)) {
        //dump($Value);
        //dump($Type);
        //dump($Field);
        //dump($Config);
        //die;
        switch ($Type) {
            case 'image':
                $Value = strtok($Value, '?');
                $imageWidth = $Config['_ImageSizeX'][$Field] == 'auto' ? '100' : $Config['_ImageSizeX'][$Field];
                $imageHeight = $Config['_ImageSizeY'][$Field] == 'auto' ? '100' : $Config['_ImageSizeY'][$Field];
                $iconWidth = $Config['_IconSizeX'][$Field] == 'auto' ? '100' : $Config['_IconSizeX'][$Field];
                $iconHeight = $Config['_IconSizeY'][$Field] == 'auto' ? '100' : $Config['_IconSizeY'][$Field];
                $uploadVars = wp_upload_dir();
                $SourceFile = str_replace($uploadVars['baseurl'], $uploadVars['basedir'], $Value);
                if (!file_exists($SourceFile)) {
                    return 'Image does not exists.';
                }
                $dim = getimagesize($SourceFile);
                $newDim = image_resize_dimensions($dim[0], $dim[1], $iconWidth, $iconHeight, true);
                if (!empty($newDim)) {
                    $Sourcepath = pathinfo($SourceFile);
                    $URLpath = pathinfo($Value);
                    $iconURL = $URLpath['dirname'] . '/' . $URLpath['filename'] . '-' . $newDim[4] . 'x' . $newDim[5] . '.' . $URLpath['extension'];
                    if (!file_exists($Sourcepath['dirname'] . '/' . $Sourcepath['filename'] . '-' . $newDim[4] . 'x' . $newDim[5] . '.' . $Sourcepath['extension'])) {
                        $image = image_resize($SourceFile, $imageWidth, $imageHeight, true);
                        $icon = image_resize($SourceFile, $iconWidth, $iconHeight, true);
                    }
                } else {
                    $iconURL = $Value;
                    $iconWidth = $dim[0];
                    $iconHeight = $dim[1];
                }
                $ClassName = '';
                if (!empty($Config['_ImageClassName'][$Field])) {
                    $ClassName = 'class="' . $Config['_ImageClassName'][$Field] . '" ';
                }
                if (!empty($Config['_IconURLOnly'][$Field])) {
                    return $iconURL;
                }
                return '<img src="' . $iconURL . '" ' . $ClassName . image_hwstring($iconWidth, $iconHeight) . '>';
                break;
            case 'mp3':
                $File = explode('?', $Value);
                $UniID = uniqid($EID . '_');
                //$ReturnData = '<span id="'.$UniID.'">'.$File[1].'</span>';
                $ReturnData = '<audio id="' . $UniID . '" src="' . $File[0] . '">unavailable</audio>';
                $_SESSION['dataform']['OutScripts'] .= "\n\t\t\t\t\tAudioPlayer.embed(\"" . $UniID . "\", {\n\t\t\t\t\t";
                if (!empty($Config['_PlayerCFG']['Autoplay'][$Field])) {
                    $_SESSION['dataform']['OutScripts'] .= " autostart: 'yes', ";
                }
                if (!empty($Config['_PlayerCFG']['Animation'][$Field])) {
                    $_SESSION['dataform']['OutScripts'] .= " animation: 'yes', ";
                }
                $_SESSION['dataform']['OutScripts'] .= "\n                                                transparentpagebg: 'yes',\n\t\t\t\t\t\tsoundFile: \"" . $File[0] . "\",\n\t\t\t\t\t\ttitles: \"" . $File[1] . "\"\n\t\t\t\t\t});\n\n\t\t\t\t";
                $_SESSION['dataform']['OutScripts'] .= "\n                                jQuery(document).ready(function(\$) {\n                                    AudioPlayer.setup(\"" . WP_PLUGIN_URL . "/db-toolkit/data_form/fieldtypes/file/player.swf\", {\n                                        width: '100%',\n                                        initialvolume: 100,\n                                        transparentpagebg: \"yes\",\n                                        left: \"000000\",\n                                        lefticon: \"FFFFFF\"\n                                    });\n                                 });";
                return $ReturnData;
                break;
            case 'file':
            case 'multi':
                if (empty($Config['_fileReturnValue'][$Field])) {
                    $Config['_fileReturnValue'][$Field] = 'iconlink';
                }
                $pathInfo = pathinfo($Value);
                $s3Enabled = false;
                $prime = $Field;
                if (!empty($Config['_CloneField'][$Field]['Master'])) {
                    $prime = $Config['_CloneField'][$Field]['Master'];
                }
                if (!empty($Config['_enableS3'][$prime]) && !empty($Config['_AWSAccessKey'][$prime]) && !empty($Config['_AWSSecretKey'][$prime])) {
                    include_once DB_TOOLKIT . 'data_form/fieldtypes/file/s3.php';
                    $s3 = new S3($Config['_AWSAccessKey'][$prime], $Config['_AWSSecretKey'][$prime]);
                    $s3Enabled = true;
                }
                switch ($Config['_fileReturnValue'][$Field]) {
                    case 'iconlink':
                        if (empty($Value)) {
                            return 'no file uploaded';
                        }
                        if (!empty($Config['_enableS3'][$prime]) && !empty($Config['_AWSAccessKey'][$prime]) && !empty($Config['_AWSSecretKey'][$prime])) {
                            $File = 'http://' . $Config['_AWSBucket'][$prime] . '.s3.amazonaws.com/' . $Value;
                        } else {
                            $File = $Value;
                        }
                        $Dets = pathinfo($File);
                        $ext = strtolower($Dets['extension']);
                        if (file_exists(WP_PLUGIN_DIR . '/db-toolkit/data_form/fieldtypes/file/icons/' . $ext . '.gif')) {
                            $Icon = '<img src="' . WP_PLUGIN_URL . '/db-toolkit/data_form/fieldtypes/file/icons/' . $ext . '.gif" align="absmiddle" />&nbsp;';
                        } else {
                            $Icon = '<img src="' . WP_PLUGIN_URL . '/db-toolkit/data_form/fieldtypes/file/icons/file.gif" align="absmiddle" />&nbsp;';
                        }
                        return '<a href="' . $File . '">' . $Icon . ' ' . basename($File) . '</a>';
                        break;
                    case 'filesize':
                        if (!empty($s3Enabled)) {
                            $object = $s3->getObjectInfo($Config['_AWSBucket'][$prime], $Value);
                            return file_return_bytes($object['size']);
                        } else {
//.........这里部分代码省略.........
开发者ID:routexl,项目名称:DB-Toolkit,代码行数:101,代码来源:functions.php


示例2: aq_resize

/**
* Title		: Aqua Resizer
* Description	: Resizes WordPress images on the fly
* Version	: 1.1.5
* Author	: Syamil MJ
* Author URI	: http://aquagraphite.com
* License	: WTFPL - http://sam.zoy.org/wtfpl/
* Documentation	: https://github.com/sy4mil/Aqua-Resizer/
*
* @param string $url - (required) must be uploaded using wp media uploader
* @param int $width - (required)
* @param int $height - (optional)
* @param bool $crop - (optional) default to soft crop
* @param bool $single - (optional) returns an array if false
* @uses wp_upload_dir()
* @uses image_resize_dimensions()
* @uses image_resize()
*
* @return str|array
*/
function aq_resize($url, $width, $height = null, $crop = null, $single = true)
{
    //validate inputs
    if (!$url or !$width) {
        return false;
    }
    //define upload path & dir
    $upload_info = wp_upload_dir();
    $upload_dir = $upload_info['basedir'];
    $upload_url = $upload_info['baseurl'];
    //check if $img_url is local
    if (strpos($url, $upload_url) === false) {
        return false;
    }
    //define path of image
    $rel_path = str_replace($upload_url, '', $url);
    $img_path = $upload_dir . $rel_path;
    //check if img path exists, and is an image indeed
    if (!file_exists($img_path) or !getimagesize($img_path)) {
        return false;
    }
    //get image info
    $info = pathinfo($img_path);
    $ext = $info['extension'];
    list($orig_w, $orig_h) = getimagesize($img_path);
    //get image size after cropping
    $dims = image_resize_dimensions($orig_w, $orig_h, $width, $height, $crop);
    $dst_w = $dims[4];
    $dst_h = $dims[5];
    //use this to check if cropped image already exists, so we can return that instead
    $suffix = "{$dst_w}x{$dst_h}";
    $dst_rel_path = str_replace('.' . $ext, '', $rel_path);
    $destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}";
    if (!$dst_h) {
        //can't resize, so return original url
        $img_url = $url;
        $dst_w = $orig_w;
        $dst_h = $orig_h;
    } elseif (file_exists($destfilename) && getimagesize($destfilename)) {
        $img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
    } else {
        $resized_img_path = image_resize($img_path, $width, $height, $crop);
        if (!is_wp_error($resized_img_path)) {
            $resized_rel_path = str_replace($upload_dir, '', $resized_img_path);
            $img_url = $upload_url . $resized_rel_path;
        } else {
            return false;
        }
    }
    //return the output
    if ($single) {
        //str return
        $image = $img_url;
    } else {
        //array return
        $image = array(0 => $img_url, 1 => $dst_w, 2 => $dst_h);
    }
    return $image;
}
开发者ID:netcon-source,项目名称:Aqua-Resizer,代码行数:79,代码来源:aq_resizer.php


示例3: image_resize

 /**
  * This function is almost equal to the image_resize (native function of wordpress)
  */
 function image_resize($file, $max_w, $max_h, $crop = false, $dest_path = null, $jpeg_quality = 90)
 {
     $image = wp_load_image($file);
     if (!is_resource($image)) {
         return new WP_Error('error_loading_image', $image);
     }
     $size = @getimagesize($file);
     if (!$size) {
         return new WP_Error('invalid_image', __('Could not read image size'), $file);
     }
     list($orig_w, $orig_h, $orig_type) = $size;
     $dims = image_resize_dimensions($orig_w, $orig_h, $max_w, $max_h, $crop);
     if (!$dims) {
         $dims = array(0, 0, 0, 0, $orig_w, $orig_h, $orig_w, $orig_h);
     }
     list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims;
     $newimage = imagecreatetruecolor($dst_w, $dst_h);
     imagecopyresampled($newimage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
     // convert from full colors to index colors, like original PNG.
     if (IMAGETYPE_PNG == $orig_type && !imageistruecolor($image)) {
         imagetruecolortopalette($newimage, false, imagecolorstotal($image));
     }
     // we don't need the original in memory anymore
     imagedestroy($image);
     $info = pathinfo($dest_path);
     $dir = $info['dirname'];
     $ext = $info['extension'];
     $name = basename($dest_path, ".{$ext}");
     $destfilename = "{$dir}/{$name}.{$ext}";
     if (IMAGETYPE_GIF == $orig_type) {
         if (!imagegif($newimage, $destfilename)) {
             return new WP_Error('resize_path_invalid', __('Resize path invalid'));
         }
     } elseif (IMAGETYPE_PNG == $orig_type) {
         if (!imagepng($newimage, $destfilename)) {
             return new WP_Error('resize_path_invalid', __('Resize path invalid'));
         }
     } else {
         // all other formats are converted to jpg
         if (!imagejpeg($newimage, $destfilename, apply_filters('jpeg_quality', $jpeg_quality, 'image_resize'))) {
             return new WP_Error('resize_path_invalid', __('Resize path invalid'));
         }
     }
     imagedestroy($newimage);
     // Set correct file permissions
     $stat = stat(dirname($destfilename));
     $perms = $stat['mode'] & 0666;
     //same permissions as parent folder, strip off the executable bits
     @chmod($destfilename, $perms);
     return $destfilename;
 }
开发者ID:karbassi,项目名称:Magic-Fields,代码行数:54,代码来源:MF_thumb.php


示例4: dynimg_generate_metadata

function dynimg_generate_metadata($meta)
{
    global $dynimg_image_sizes;
    foreach ($dynimg_image_sizes as $sizename => $size) {
        // figure out what size WP would make this:
        $newsize = image_resize_dimensions($meta['width'], $meta['height'], $size['width'], $size['height'], $size['crop']);
        if ($newsize) {
            $info = pathinfo($meta['file']);
            $ext = $info['extension'];
            $name = wp_basename($meta['file'], ".{$ext}");
            $suffix = "{$newsize[4]}x{$newsize[5]}";
            if ($size['crop']) {
                $suffix .= 'c';
            }
            // build the fake meta entry for the size in question
            $resized = array('file' => "{$name}-{$suffix}.{$ext}", 'width' => $newsize[4], 'height' => $newsize[5]);
            $meta['sizes'][$sizename] = $resized;
        }
    }
    return $meta;
}
开发者ID:vanlong200880,项目名称:uni,代码行数:21,代码来源:dynamic-image-resizer.php


示例5: resize

 /**
  * Resizes current image.
  *
  * At minimum, either a height or width must be provided.
  * If one of the two is set to null, the resize will
  * maintain aspect ratio according to the provided dimension.
  *
  * @access public
  *
  * @param  int|null $max_w Image width.
  * @param  int|null $max_h Image height.
  * @param  boolean  $crop
  * @return boolean|WP_Error
  */
 public function resize($max_w, $max_h, $crop = false)
 {
     if ($this->size['width'] == $max_w && $this->size['height'] == $max_h) {
         return true;
     }
     $dims = image_resize_dimensions($this->size['width'], $this->size['height'], $max_w, $max_h, $crop);
     if (!$dims) {
         return new WP_Error('error_getting_dimensions', __('Could not calculate resized image dimensions'));
     }
     list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims;
     if ($crop) {
         return $this->crop($src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h);
     }
     try {
         if ($this->mime_type === 'image/gif') {
             $this->image->scaleImage($dst_w, $dst_h);
         } else {
             $this->image->smartResize($dst_w, $dst_h, false);
         }
     } catch (Exception $e) {
         return new WP_Error('image_resize_error', $e->getMessage());
     }
     return $this->update_size($dst_w, $dst_h);
 }
开发者ID:BBGInnovate,项目名称:DEPRECATED-wp-tevko-responsive-images,代码行数:38,代码来源:class-wp-image-editor-respimg.php


示例6: image_resize

/**
 * Scale down an image to fit a particular size and save a new copy of the image.
 *
 * The PNG transparency will be preserved using the function, as well as the
 * image type. If the file going in is PNG, then the resized image is going to
 * be PNG. The only supported image types are PNG, GIF, and JPEG.
 *
 * Some functionality requires API to exist, so some PHP version may lose out
 * support. This is not the fault of WordPress (where functionality is
 * downgraded, not actual defects), but of your PHP version.
 *
 * @since 2.5.0
 *
 * @param string $file Image file path.
 * @param int $max_w Maximum width to resize to.
 * @param int $max_h Maximum height to resize to.
 * @param bool $crop Optional. Whether to crop image or resize.
 * @param string $suffix Optional. File Suffix.
 * @param string $dest_path Optional. New image file path.
 * @param int $jpeg_quality Optional, default is 90. Image quality percentage.
 * @return mixed WP_Error on failure. String with new destination path. Array of dimensions from {@link image_resize_dimensions()}
 */
function image_resize($file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90)
{
    $image = wp_load_image($file);
    if (!is_resource($image)) {
        return new WP_Error('error_loading_image', $image);
    }
    list($orig_w, $orig_h, $orig_type) = getimagesize($file);
    $dims = image_resize_dimensions($orig_w, $orig_h, $max_w, $max_h, $crop);
    if (!$dims) {
        return $dims;
    }
    list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims;
    $newimage = imagecreatetruecolor($dst_w, $dst_h);
    // preserve PNG transparency
    if (IMAGETYPE_PNG == $orig_type && function_exists('imagealphablending') && function_exists('imagesavealpha')) {
        imagealphablending($newimage, false);
        imagesavealpha($newimage, true);
    }
    imagecopyresampled($newimage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
    // we don't need the original in memory anymore
    imagedestroy($image);
    // $suffix will be appended to the destination filename, just before the extension
    if (!$suffix) {
        $suffix = "{$dst_w}x{$dst_h}";
    }
    $info = pathinfo($file);
    $dir = $info['dirname'];
    $ext = $info['extension'];
    $name = basename($file, ".{$ext}");
    if (!is_null($dest_path) and $_dest_path = realpath($dest_path)) {
        $dir = $_dest_path;
    }
    $destfilename = "{$dir}/{$name}-{$suffix}.{$ext}";
    if ($orig_type == IMAGETYPE_GIF) {
        if (!imagegif($newimage, $destfilename)) {
            return new WP_Error('resize_path_invalid', __('Resize path invalid'));
        }
    } elseif ($orig_type == IMAGETYPE_PNG) {
        if (!imagepng($newimage, $destfilename)) {
            return new WP_Error('resize_path_invalid', __('Resize path invalid'));
        }
    } else {
        // all other formats are converted to jpg
        $destfilename = "{$dir}/{$name}-{$suffix}.jpg";
        if (!imagejpeg($newimage, $destfilename, apply_filters('jpeg_quality', $jpeg_quality, 'image_resize'))) {
            return new WP_Error('resize_path_invalid', __('Resize path invalid'));
        }
    }
    imagedestroy($newimage);
    // Set correct file permissions
    $stat = stat(dirname($destfilename));
    $perms = $stat['mode'] & 0666;
    //same permissions as parent folder, strip off the executable bits
    @chmod($destfilename, $perms);
    return $destfilename;
}
开发者ID:jennyHsiao,项目名称:projects.chrislkeller.com,代码行数:78,代码来源:media.php


示例7: resize

 /**
  * Resizes current image.
  *
  * At minimum, either a height or width must be provided.
  * If one of the two is set to null, the resize will
  * maintain aspect ratio according to the provided dimension.
  *
  * @since 3.5.0
  * @access public
  *
  * @param  int|null $max_w Image width.
  * @param  int|null $max_h Image height.
  * @param  bool     $crop
  * @return bool|WP_Error
  */
 public function resize($max_w, $max_h, $crop = false)
 {
     if ($this->size['width'] == $max_w && $this->size['height'] == $max_h) {
         return true;
     }
     $dims = image_resize_dimensions($this->size['width'], $this->size['height'], $max_w, $max_h, $crop);
     if (!$dims) {
         return new WP_Error('error_getting_dimensions', __('Could not calculate resized image dimensions'));
     }
     list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims;
     if ($crop) {
         return $this->crop($src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h);
     }
     // Execute the resize
     $thumb_result = $this->thumbnail_image($dst_w, $dst_h);
     if (is_wp_error($thumb_result)) {
         return $thumb_result;
     }
     return $this->update_size($dst_w, $dst_h);
 }
开发者ID:aaemnnosttv,项目名称:develop.git.wordpress.org,代码行数:35,代码来源:class-wp-image-editor-imagick.php


示例8: thumb

 /** Uses WP's Image Editor Class to resize and filter images
  * Inspired by: https://github.com/sy4mil/Aqua-Resizer/blob/master/aq_resizer.php
  *
  * @param $url string the local image URL to manipulate
  * @param $params array the options to perform on the image. Keys and values supported:
  *          'width' int pixels
  *          'height' int pixels
  *          'opacity' int 0-100
  *          'color' string hex-color #000000-#ffffff
  *          'grayscale' bool
  *          'crop' bool
  *          'negate' bool
  * @param $single boolean, if false then an array of data will be returned
  * @return string|array
  */
 public static function thumb($url, $params = array(), $single = true)
 {
     extract($params);
     //validate inputs
     if (!$url) {
         return false;
     }
     //define upload path & dir
     $upload_info = wp_upload_dir();
     $upload_dir = $upload_info['basedir'];
     $upload_url = $upload_info['baseurl'];
     $theme_url = get_template_directory_uri();
     $theme_dir = get_template_directory();
     // find the path of the image. Perform 2 checks:
     // #1 check if the image is in the uploads folder
     if (strpos($url, $upload_url) !== false) {
         $rel_path = str_replace($upload_url, '', $url);
         $img_path = $upload_dir . $rel_path;
         // #2 check if the image is in the current theme folder
     } else {
         if (strpos($url, $theme_url) !== false) {
             $rel_path = str_replace($theme_url, '', $url);
             $img_path = $theme_dir . $rel_path;
         }
     }
     // Fail if we can't find the image in our WP local directory
     if (empty($img_path)) {
         return $url;
     }
     //check if img path exists, and is an image indeed
     if (!@file_exists($img_path) or !getimagesize($img_path)) {
         return $url;
     }
     // This is the filename
     $basename = basename($img_path);
     //get image info
     $info = pathinfo($img_path);
     $ext = $info['extension'];
     list($orig_w, $orig_h) = getimagesize($img_path);
     // support percentage dimensions. compute percentage based on
     // the original dimensions
     if (isset($width)) {
         if (stripos($width, '%') !== false) {
             $width = (int) ((double) str_replace('%', '', $width) / 100 * $orig_w);
         }
     }
     if (isset($height)) {
         if (stripos($height, '%') !== false) {
             $height = (int) ((double) str_replace('%', '', $height) / 100 * $orig_h);
         }
     }
     // The only purpose of this is to detemine the final width and height
     // without performing any actual image manipulation, which will be used
     // to check whether a resize was previously done.
     if (isset($width)) {
         //get image size after cropping
         $dims = image_resize_dimensions($orig_w, $orig_h, $width, isset($height) ? $height : null, isset($crop) ? $crop : false);
         $dst_w = $dims[4];
         $dst_h = $dims[5];
     }
     // create the suffix for the saved file
     // we can use this to check whether we need to create a new file or just use an existing one.
     $suffix = (string) filemtime($img_path) . (isset($width) ? str_pad((string) $width, 5, '0', STR_PAD_LEFT) : '00000') . (isset($height) ? str_pad((string) $height, 5, '0', STR_PAD_LEFT) : '00000') . (isset($opacity) ? str_pad((string) $opacity, 3, '0', STR_PAD_LEFT) : '100') . (isset($color) ? str_pad(preg_replace('#^\\##', '', $color), 8, '0', STR_PAD_LEFT) : '00000000') . (isset($grayscale) ? $grayscale ? '1' : '0' : '0') . (isset($crop) ? $crop ? '1' : '0' : '0') . (isset($negate) ? $negate ? '1' : '0' : '0');
     $suffix = self::base_convert_arbitrary($suffix, 10, 36);
     // use this to check if cropped image already exists, so we can return that instead
     $dst_rel_path = str_replace('.' . $ext, '', basename($img_path));
     // If opacity is set, change the image type to png
     if (isset($opacity)) {
         $ext = 'png';
     }
     // Create the upload subdirectory, this is where
     // we store all our generated images
     if (defined('BFITHUMB_UPLOAD_DIR')) {
         $upload_dir .= "/" . BFITHUMB_UPLOAD_DIR;
         $upload_url .= "/" . BFITHUMB_UPLOAD_DIR;
     } else {
         $upload_dir .= "/bfi_thumb";
         $upload_url .= "/bfi_thumb";
     }
     if (!is_dir($upload_dir)) {
         wp_mkdir_p($upload_dir);
     }
     // desination paths and urls
     $destfilename = "{$upload_dir}/{$dst_rel_path}-{$suffix}.{$ext}";
     $img_url = "{$upload_url}/{$dst_rel_path}-{$suffix}.{$ext}";
//.........这里部分代码省略.........
开发者ID:dgordon86,项目名称:breakbiodark,代码行数:101,代码来源:bfithumb.class.php


示例9: image_get_intermediate_size

/**
 * Retrieves the image's intermediate size (resized) path, width, and height.
 *
 * The $size parameter can be an array with the width and height respectively.
 * If the size matches the 'sizes' metadata array for width and height, then it
 * will be used. If there is no direct match, then the nearest image size larger
 * than the specified size will be used. If nothing is found, then the function
 * will break out and return false.
 *
 * The metadata 'sizes' is used for compatible sizes that can be used for the
 * parameter $size value.
 *
 * The url path will be given, when the $size parameter is a string.
 *
 * If you are passing an array for the $size, you should consider using
 * add_image_size() so that a cropped version is generated. It's much more
 * efficient than having to find the closest-sized image and then having the
 * browser scale down the image.
 *
 * @since 2.5.0
 *
 * @param int          $post_id Attachment ID.
 * @param array|string $size    Optional. Image size. Accepts any valid image size, or an array
 *                              of width and height values in pixels (in that order).
 *                              Default 'thumbnail'.
 * @return false|array $data {
 *     Array of file relative path, width, and height on success. Additionally includes absolute
 *     path and URL if registered size is passed to $size parameter. False on failure.
 *
 *     @type string $file   Image's path relative to uploads directory
 *     @type int    $width  Width of image
 *     @type int    $height Height of image
 *     @type string $path   Optional. Image's absolute filesystem path. Only returned if registered
 *                          size is passed to `$size` parameter.
 *     @type string $url    Optional. Image's URL. Only returned if registered size is passed to `$size`
 *                          parameter.
 * }
 */
function image_get_intermediate_size($post_id, $size = 'thumbnail')
{
    if (!is_array($imagedata = wp_get_attachment_metadata($post_id))) {
        return false;
    }
    // get the best one for a specified set of dimensions
    if (is_array($size) && !empty($imagedata['sizes'])) {
        $candidates = array();
        foreach ($imagedata['sizes'] as $_size => $data) {
            // If there's an exact match to an existing image size, short circuit.
            if ($data['width'] == $size[0] && $data['height'] == $size[1]) {
                list($data['width'], $data['height']) = image_constrain_size_for_editor($data['width'], $data['height'], $size);
                /** This filter is documented in wp-includes/media.php */
                return apply_filters('image_get_intermediate_size', $data, $post_id, $size);
            }
            // If it's not an exact match but it's at least the dimensions requested.
            if ($data['width'] >= $size[0] && $data['height'] >= $size[1]) {
                $candidates[$data['width'] * $data['height']] = $_size;
            }
        }
        if (!empty($candidates)) {
            // find for the smallest image not smaller than the desired size
            ksort($candidates);
            foreach ($candidates as $_size) {
                $data = $imagedata['sizes'][$_size];
                // Skip images with unexpectedly divergent aspect ratios (crops)
                // First, we calculate what size the original image would be if constrained to a box the size of the current image in the loop
                $maybe_cropped = image_resize_dimensions($imagedata['width'], $imagedata['height'], $data['width'], $data['height'], false);
                // If the size doesn't match within one pixel, then it is of a different aspect ratio, so we skip it, unless it's the thumbnail size
                if ('thumbnail' != $_size && (!$maybe_cropped || $maybe_cropped[4] != $data['width'] && $maybe_cropped[4] + 1 != $data['width'] || $maybe_cropped[5] != $data['height'] && $maybe_cropped[5] + 1 != $data['height'])) {
                    continue;
                }
                // If we're still here, then we're going to use this size.
                list($data['width'], $data['height']) = image_constrain_size_for_editor($data['width'], $data['height'], $size);
                /** This filter is documented in wp-includes/media.php */
                return apply_filters('image_get_intermediate_size', $data, $post_id, $size);
            }
        }
    }
    if (is_array($size) || empty($size) || empty($imagedata['sizes'][$size])) {
        return false;
    }
    $data = $imagedata['sizes'][$size];
    // include the full filesystem path of the intermediate file
    if (empty($data['path']) && !empty($data['file'])) {
        $file_url = wp_get_attachment_url($post_id);
        $data['path'] = path_join(dirname($imagedata['file']), $data['file']);
        $data['url'] = path_join(dirname($file_url), $data['file']);
    }
    /**
     * Filter the output of image_get_intermediate_size()
     *
     * @since 4.4.0
     *
     * @see image_get_intermediate_size()
     *
     * @param array        $data    Array of file relative path, width, and height on success. May also include
     *                              file absolute path and URL.
     * @param int          $post_id The post_id of the image attachment
     * @param string|array $size    Registered image size or flat array of initially-requested height and width
     *                              dimensions (in that order).
     */
//.........这里部分代码省略.........
开发者ID:nakamuraagatha,项目名称:reseptest,代码行数:101,代码来源:media.php


示例10: image_get_intermediate_size

/**
 * Retrieves the image's intermediate size (resized) path, width, and height.
 *
 * The $size parameter can be an array with the width and height respectively.
 * If the size matches the 'sizes' metadata array for width and height, then it
 * will be used. If there is no direct match, then the nearest image size larger
 * than the specified size will be used. If nothing is found, then the function
 * will break out and return false.
 *
 * The metadata 'sizes' is used for compatible sizes that can be used for the
 * parameter $size value.
 *
 * The url path will be given, when the $size parameter is a string.
 *
 * If you are passing an array for the $size, you should consider using
 * add_image_size() so that a cropped version is generated. It's much more
 * efficient than having to find the closest-sized image and then having the
 * browser scale down the image.
 *
 * @since 2.5.0
 *
 * @param int          $post_id Attachment ID.
 * @param array|string $size    Optional. Registered image size to retrieve or flat array of height
 *                              and width dimensions. Default 'thumbnail'.
 * @return false|array False on failure or array of file path, width, and height on success.
 */
function image_get_intermediate_size($post_id, $size = 'thumbnail')
{
    if (!is_array($imagedata = wp_get_attachment_metadata($post_id))) {
        return false;
    }
    // get the best one for a specified set of dimensions
    if (is_array($size) && !empty($imagedata['sizes'])) {
        $areas = array();
        foreach ($imagedata['sizes'] as $_size => $data) {
            // already cropped to width or height; so use this size
            if ($data['width'] == $size[0] && $data['height'] <= $size[1] || $data['height'] == $size[1] && $data['width'] <= $size[0]) {
                $file = $data['file'];
                list($width, $height) = image_constrain_size_for_editor($data['width'], $data['height'], $size);
                return compact('file', 'width', 'height');
            }
            // add to lookup table: area => size
            $areas[$data['width'] * $data['height']] = $_size;
        }
        if (!$size || !empty($areas)) {
            // find for the smallest image not smaller than the desired size
            ksort($areas);
            foreach ($areas as $_size) {
                $data = $imagedata['sizes'][$_size];
                if ($data['width'] >= $size[0] || $data['height'] >= $size[1]) {
                    // Skip images with unexpectedly divergent aspect ratios (crops)
                    // First, we calculate what size the original image would be if constrained to a box the size of the current image in the loop
                    $maybe_cropped = image_resize_dimensions($imagedata['width'], $imagedata['height'], $data['width'], $data['height'], false);
                    // If the size doesn't match within one pixel, then it is of a different aspect ratio, so we skip it, unless it's the thumbnail size
                    if ('thumbnail' != $_size && (!$maybe_cropped || $maybe_cropped[4] != $data['width'] && $maybe_cropped[4] + 1 != $data['width'] || $maybe_cropped[5] != $data['height'] && $maybe_cropped[5] + 1 != $data['height'])) {
                        continue;
                    }
                    // If we're still here, then we're going to use this size
                    $file = $data['file'];
                    list($width, $height) = image_constrain_size_for_editor($data['width'], $data['height'], $size);
                    return compact('file', 'width', 'height');
                }
            }
        }
    }
    if (is_array($size) || empty($size) || empty($imagedata['sizes'][$size])) {
        return false;
    }
    $data = $imagedata['sizes'][$size];
    // include the full filesystem path of the intermediate file
    if (empty($data['path']) && !empty($data['file'])) {
        $file_url = wp_get_attachment_url($post_id);
        $data['path'] = path_join(dirname($imagedata['file']), $data['file']);
        $data['url'] = path_join(dirname($file_url), $data['file']);
    }
    return $data;
}
开发者ID:nstungxd,项目名称:F2CA5,代码行数:77,代码来源:media.php


示例11: aq_resize

 function aq_resize($url, $width, $height = null, $crop = null, $single = true)
 {
     if (of_get_option('image_resizing', '1') !== '1') {
         return $url;
     }
     //validate inputs
     if (!$url or !$width) {
         return false;
     }
     //set dimensions
     $aq_width = $width;
     $aq_height = $height;
     //define upload path & dir
     $upload_info = wp_upload_dir();
     $upload_dir = $upload_info['basedir'];
     $upload_url = $upload_info['baseurl'];
     //check if $img_url is local
     if (strpos($url, $upload_url) === false) {
         return false;
     }
     //define path of image
     $rel_path = str_replace($upload_url, '', $url);
     $img_path = $upload_dir . $rel_path;
     //check if img path exists, and is an image indeed
     if (!file_exists($img_path) or !getimagesize($img_path)) {
         return false;
     }
     //get image info
     $info = pathinfo($img_path);
     $ext = $info['extension'];
     list($orig_w, $orig_h) = getimagesize($img_path);
     //get image size after cropping
     $dims = image_resize_dimensions($orig_w, $orig_h, $aq_width, $aq_height, $crop);
     $dst_w = $dims[4];
     $dst_h = $dims[5];
     //use this to check if cropped image already exists, so we can return that instead
     $suffix = "{$dst_w}x{$dst_h}";
     $dst_rel_path = str_replace('.' . $ext, '', $rel_path);
     $destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}";
     if (!$dst_h) {
         //can't resize, so return original url
         $img_url = $url;
         $dst_w = $orig_w;
         $dst_h = $orig_h;
     } elseif (file_exists($destfilename) && getimagesize($destfilename)) {
         $img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
     } else {
         $editor = wp_get_image_editor($img_path);
         if (is_wp_error($editor) || is_wp_error($editor->resize($aq_width, $aq_height, $crop))) {
             return false;
         }
         $editor->set_quality(100);
         // Added by WPExplorer
         $resized_file = $editor->save();
         if (!is_wp_error($resized_file)) {
             $resized_rel_path = str_replace($upload_dir, '', $resized_file['path']);
             $img_url = $upload_url . $resized_rel_path;
         } else {
             return false;
         }
     }
     //return the output
     if ($single) {
         //str return
         $image = $img_url;
     } else {
         //array return
         $image = array(0 => $img_url, 1 => $dst_w, 2 => $dst_h);
     }
     // RETINA Support - Added by WPExplorer --------------------------------------------------------------->
     if (of_get_option('retina', '1') == '1') {
         $retina_w = $dst_w * 2;
         $retina_h = $dst_h * 2;
         //get image size after cropping
         $dims_x2 = image_resize_dimensions($orig_w, $orig_h, $retina_w, $retina_h, $crop);
         $dst_x2_w = $dims_x2[4];
         $dst_x2_h = $dims_x2[5];
         // If possible lets make the @2x image
         if ($dst_x2_h) {
             //@2x image url
             $destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}@2x.{$ext}";
             //check if retina image exists
             if (file_exists($destfilename) && getimagesize($destfilename)) {
                 // already exists, do nothing
             } else {
                 // doesnt exist, lets create it
                 $editor = wp_get_image_editor($img_path);
                 if (!is_wp_error($editor)) {
                     $editor->resize($retina_w, $retina_h, $crop);
                     $editor->set_quality(100);
                     $filename = $editor->generate_filename($dst_w . 'x' . $dst_h . '@2x');
                     $editor = $editor->save($filename);
                 }
             }
         }
     }
     // Return image --------------------------------------------------------------->
     return $image;
 }
开发者ID:peternem,项目名称:vlt-wp,代码行数:99,代码来源:aqua-resizer.php


示例12: removeCustomImageSizes

 /**
  * Removes generated custom image sizes.
  * @param int $post_id
  * @return void
  */
 public function removeCustomImageSizes($post_id)
 {
     $file_dir = get_attached_file($post_id);
     if (empty($file_dir)) {
         return;
     }
     $imageSizes = $this->getCustomImageSizes();
     if (!$imageSizes) {
         return;
     }
     $file_dir_info = pathinfo($file_dir);
     $file_base_dir = isset($file_dir_info['dirname']) ? $file_dir_info['dirname'] : '';
     $file_name = isset($file_dir_info['filename']) ? $file_dir_info['filename'] : '';
     $file_ext = isset($file_dir_info['extension']) ? $file_dir_info['extension'] : '';
     foreach ($imageSizes as $size) {
         $crop = $size['crop'];
         $width = $size['width'];
         $height = $size['height'];
         if (false == $crop) {
             // get image size after cropping
             list($orig_w, $orig_h) = getimagesize($file_dir);
             $dims = image_resize_dimensions($orig_w, $orig_h, $width, $height, $crop);
             $width = $dims[4];
             $height = $dims[5];
         }
         $file = $file_base_dir . '/' . $file_name . '-' . $width . 'x' . $height . '.' . $file_ext;
         if (!file_exists($file)) {
             continue;
         }
         if (unlink($file)) {
             // files remove
         } else {
             // files not remove
         }
     }
 }
开发者ID:j-kenneth,项目名称:Expeero,代码行数:41,代码来源:TdImageManager.php


示例13: process

 /**
  * Run image resizing function
  *
  * @since 1.0.0
  */
 public function process($args)
 {
     // Args must be an array
     if (!is_array($args)) {
         print_r('Fatal Error: Image resize args are not an array, you must update your template files.');
         return false;
     }
     // Default args
     $defaults = array('image' => null, 'width' => '9999', 'height' => '9999', 'crop' => 'center-center', 'retina' => false, 'return' => 'array');
     // Parse args
     $args = wp_parse_args($args, $defaults);
     // Extract args
     extract($args);
     // If URL isn't defined return
     if (!$image) {
         return;
     }
     // Sanitize inputs
     $width = intval($width);
     $height = intval($height);
     // Set width and height to '9999' if empty
     $width = $width ? $width : '9999';
     $height = $height ? $height : '9999';
     // Set crop to center-center if empty
     $crop = $crop ? $crop : 'center-center';
     // Sanitize crop and add crop suffix
     $crop_suffix = '';
     $crop = $height >= '9999' ? false : $crop;
     // Define upload path & dir
     $upload_info = wp_upload_dir();
     $upload_dir = $upload_info['basedir'];
     $upload_url = $upload_info['baseurl'];
     // Define path of image
     $rel_path = str_replace($upload_url, '', $image);
     $img_path = $upload_dir . $rel_path;
     // Add crop_suffix if $crop isn't false or empty and image resizing is enabled
     if ($crop && wpex_get_mod('image_resizing', true)) {
         if (is_array($crop)) {
             $crop_suffix = array_combine($crop, $crop);
             $crop_suffix = implode('-', $crop_suffix);
         } elseif ('center-center' != $crop) {
             $crop_suffix = $crop;
             $crop = explode('-', $crop);
         }
     }
     // If image width and height are both 9999 and size is empty return full image
     if ('9999' == $width && '9999' == $height) {
         // Return for retina images
         if ($retina) {
             return;
         }
         // Set main image to the full URL
         $img_url = $image;
         // Get width and height
         $info = pathinfo($img_path);
         $ext = $info['extension'];
         list($orig_w, $orig_h) = getimagesize($img_path);
     } else {
         // Set resize dimensions
         $resize_width = $width;
         $resize_height = $height;
         // If $img_url isn't local return full image
         if (strpos($image, $upload_url) === false) {
             $img_url = $image;
         } else {
             // Check if img path exists, and is an image indeed if not return full img
             if (!file_exists($img_path) or !getimagesize($img_path)) {
                 $img_url = $image;
             } else {
                 // Get image info
                 $info = pathinfo($img_path);
                 $ext = $info['extension'];
                 list($orig_w, $orig_h) = getimagesize($img_path);
                 // Get image size after cropping
                 $dims = image_resize_dimensions($orig_w, $orig_h, $resize_width, $resize_height, $crop);
                 $dst_w = $dims[4];
                 $dst_h = $dims[5];
                 // Can't resize, so return original url
                 if (!$dims) {
                     // Set values equal to original image
                     $img_url = $image;
                     $dst_w = $orig_w;
                     $dst_h = $orig_h;
                     // Return false for retina
                     if ($retina) {
                         return false;
                     }
                 } else {
                     // Define image saving destination
                     $dst_rel_path = str_replace('.' . $ext, '', $rel_path);
                     // Suffix
                     $suffix = $dst_w . 'x' . $dst_h;
                     // Sanitize suffix
                     $suffix = $crop_suffix ? $crop_suffix . '-' . $suffix : $suffix;
                     // Check original image destination
//.........这里部分代码省略.........
开发者ID:iq007,项目名称:MadScape,代码行数:101,代码来源:image-resize.php


示例14: simulate_image_make_intermediate_size

 /**
  * Method for testing if an image WOULD be resized
  * Simulates the validation that occurs prior to actually beginning the resize
  * process that would negate the need for or prevent the image from being resized.
  *
  * We use image_make_intermediate_size() to create our images
  * This method recreates that. See media.php
  *
  * @since       0.1.5
  * @uses        wp_load_image() WP function
  * @uses        image_resize_dimensions() WP function
  */
 public static function simulate_image_make_intermediate_size($file, $width, $height, $crop = false)
 {
     // Begin image_make_intermediate_size($file, $width, $height, $crop=false)
     if ($width || $height) {
         // Begin image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 )
         $image = wp_load_image($file);
         if (!is_resource($image)) {
             return FALSE;
         }
         //return new WP_Error( 'error_loading_image', $image, $file );
         $size = @getimagesize($file);
         if (!$size) {
             return FALSE;
         }
         //return new WP_Error('invalid_image', __('Could not read image size'), $file);
         list($orig_w, $orig_h, $orig_type) = $size;
         $dims = image_resize_dimensions($orig_w, $orig_h, $width, $height, $crop);
         // $max_w, $max_h
        

鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP image_size_input_fields函数代码示例发布时间:2022-05-15
下一篇:
PHP image_resize函数代码示例发布时间: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