2017-01-23 98 views
0

我一直在尝试调整我的默认主题图像滑块大小,无法将窗口大小调整为特定大小。任何人都可以告诉我,为了调整滑块的宽度和高度,需要对代码做些什么?调整图像滑块大小

如果您要裁剪图像您的愿望,大小
+1

_“任何人都可以告诉我,为了调整滑块的宽度和高度,需要对代码做些什么?”_没有代码出现在问题中?请参阅http://stackoverflow.com/help/mcve – guest271314

回答

0

然后在functions.php文件

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

下面的代码使用,并得到这个形象。

echo wp_get_attachment_image($id, $name); 

或者如果你想调整大小适当的长宽比的图像,然后使用这个功能,可能会帮助你。

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); 
} 

我调整了我的图像与我的项目中的这个功能。