1

func.php 文件,当图像上传到网站时,它会在其中生成缩略图。我了解如何使圆角以 5 为半径进行圆化,但由于某种原因,我现在很难将圆角合并到我的代码中,请帮助:

<?php
function create_thumb($directory, $image, $destination) {
  $image_file = $image;
  $image = $directory.$image;

if (file_exists($image)) {

$source_size = getimagesize($image);

if ($source_size !== false) {

  $thumb_width = 100;
  $thumb_height = 100;

  switch($source_size['mime']) {
    case 'image/jpeg':
         $source = imagecreatefromjpeg($image);
    break;
    case 'image/png':
         $source = imagecreatefrompng($image);
    break;
    case 'image/gif':
         $source = imagecreatefromgif($image);
    break;
  }

  $source_aspect = round(($source_size[0] / $source_size[1]), 1);
  $thumb_aspect = round(($thumb_width / $thumb_height), 1);

  if ($source_aspect < $thumb_aspect) {
    $new_size = array($thumb_width, ($thumb_width / $source_size[0]) * $source_size[1]);
    $source_pos = array(0, ($new_size[1] - $thumb_height) / 2);
  } else if ($source_aspect > $thumb_aspect) {
    $new_size = array(($thumb_width / $source_size[1]) * $source_size[0], $thumb_height);
    $source_pos = array(($new_size[0] - $thumb_width) / 2, 0);
  } else {
    $new_size = array($thumb_width, $thumb_height);
    $source_pos = array(0, 0);
  }

  if ($new_size[0] < 1) $new_size[0] = 1;
  if ($new_size[1] < 1) $new_size[1] = 1;

  $thumb = imagecreatetruecolor($thumb_width, $thumb_height);
  imagecopyresampled($thumb, $source, 0, 0, $source_pos[0], $source_pos[1], $new_size[0], $new_size[1], $source_size[0], $source_size[1]);

  switch($source_size['mime']) {
    case 'image/jpeg':
         imagejpeg($thumb, $destination.$image_file);
    break;
    case 'image/png':
          imagepng($thumb, $destination.$image_file);
    break;
    case 'image/gif':
         imagegif($thumb, $destination.$image_file);
    break;
  }


}

  }
}
?>
4

1 回答 1

2

此代码看起来像是图像制作过程的一部分
要设置图像样式,您需要处理该文件的输出您是否有为客户端

生成的代码? 如果是这样,那么给每个人一个班级并使用给它角落HTML
imgCSS

.ui-corner-all { -moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px; }
于 2012-08-14T20:02:06.083 回答