简体   繁体   English

调整图像滑块大小

[英]Resize image slider

I have been trying to resize my default theme image slider and was unable to resize the window to a specific size. 我一直在尝试调整默认主题图像滑块的大小,但无法将窗口调整为特定大小。 Can anyone please tell me what additions i need to do to this code in order to resize the slider width and height? 谁能告诉我为调整滑块的宽度和高度的大小,我需要对代码进行哪些添加?

if you want to crop image to your desire size then use below code in your functions.php file 如果您想将图像裁剪为所需的大小,请在functions.php文件中使用以下代码

add_image_size( $name, $width, $height, $crop );

and get this image. 并获得此图像。

echo wp_get_attachment_image( $id, $name );

or if you want resize image with proper aspect ratio, then use this function, may be it will help u. 或者如果您想以合适的宽高比调整图像大小,请使用此功能,可能对您有所帮助。

 function resize ($width, $height ){
    /* Get original image x y*/
    list($w, $h) = getimagesize($_FILES['image']['tmp_name']);
    /* calculate new image size with ratio */
    $ratio = max( $width/$w, $height/$h);
    $h = ceil($height / $ratio);
    $x = ($w - $width / $ratio) / 2;
    $w = ceil($width / $ratio);
    /* new file name */
    $path = 'uploads/'.$width.'x'.$height.'_'.$_FILES['image']['name'];
    /* read binary data from image file */
    $imgString = file_get_contents($_FILES['image']['tmp_name']);
    /* create image from string */
    $image = imagecreatefromstring($imgString);
    $tmp = imagecreatetruecolor($width, $height);
    imagecopyresampled($tmp, $image, 0, 0, $x, 0, $width, $height, $w, $h);
    /* Save image */
    switch ($_FILES['image']['type']) {
        case 'image/jpeg':
            imagejpeg($tmp, $path, 100);
            break;
        case 'image/png':
            imagepng($tmp, $path, 0);
            break;
        case 'image/gif':
            imagegif($tmp, $path);
            break;
        default:
            exit;
            break;
    }
    return $path;
    /* cleanup memory */
    imagedestroy($image);
    imagedestroy($tmp);
}

i resize my image with this function in my project. 我在我的项目中使用此功能调整图像大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM