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);
}
我調整了我的圖像與我的項目中的這個功能。
_「任何人都可以告訴我,爲了調整滑塊的寬度和高度,需要對代碼做些什麼?」_沒有代碼出現在問題中?請參閱http://stackoverflow.com/help/mcve – guest271314