function modeImageThumb($srcFile, $dstFile, $dstX, $dstY) { global $db_quality; $imgdata = array(); list($imgdata['width'], $imgdata['height'], $imgdata['type']) = @getimagesize($srcFile); switch ($imgdata['type']) { case 1: $imgdata['type'] = 'gif'; break; case 2: $imgdata['type'] = 'jpeg'; break; case 3: $imgdata['type'] = 'png'; break; default: return false; } if (!empty($imgdata) && function_exists('imagecreatefrom' . $imgdata['type'])) { $imagecreatefromtype = 'imagecreatefrom' . $imgdata['type']; } else { return false; } $imgdata['source'] = $imagecreatefromtype($srcFile); !$imgdata['width'] && ($imgdata['width'] = imagesx($imgdata['source'])); !$imgdata['height'] && ($imgdata['height'] = imagesy($imgdata['source'])); list($imagecreate, $imagecopyre) = GetImageCreate($imgdata['type']); $thumb = $imagecreate($dstX, $dstY); $color = @ImageColorAllocate($thumb, 255, 255, 255); @imagefilledrectangle($thumb, 0, 0, $dstX, $dstY, $color); $pX = $pY = $pW = $pH = 0; if ($dstX && !$dstY) { $dstY = $imgdata['height'] * $dstX / $imgdata['width']; } else { if (!$dstX && $dstY) { $dstX = $imgdata['width'] * $dstY / $imgdata['height']; } } $p = $dstX / $dstY; if ($imgdata['width'] / $imgdata['height'] > $p) { //说明宽度太大 $pH = $dstY; $pW = $pH * $p; $imgdata['width'] = $imgdata['height'] * $p; } else { $pW = $dstX; $pH = $pW / $p; $imgdata['height'] = $imgdata['width'] / $p; } $imagecopyre($thumb, $imgdata['source'], 0, 0, 0, 0, $pW, $pH, $imgdata['width'], $imgdata['height']); MakeImage($imgdata['type'], $thumb, $dstFile, $db_quality); imagedestroy($thumb); return 1; }
function modeImageThumb($srcFile, $dstFile, $dstX, $dstY) { $imgdata = array(); list($imgdata['width'], $imgdata['height'], $imgdata['type']) = getimagesize($srcFile); switch ($imgdata['type']) { case 1: $imgdata['type'] = 'gif'; break; case 2: $imgdata['type'] = 'jpeg'; break; case 3: $imgdata['type'] = 'png'; break; default: return false; } if (!empty($imgdata) && function_exists('imagecreatefrom' . $imgdata['type'])) { $imagecreatefromtype = 'imagecreatefrom' . $imgdata['type']; } else { return false; } $imgdata['source'] = $imagecreatefromtype($srcFile); !$imgdata['width'] && ($imgdata['width'] = imagesx($imgdata['source'])); !$imgdata['height'] && ($imgdata['height'] = imagesy($imgdata['source'])); list($imagecreate, $imagecopyre) = GetImageCreate($imgdata['type']); $thumb = $imagecreate($dstX, $dstY); $color = @ImageColorAllocate($thumb, 255, 255, 255); @imagefilledrectangle($thumb, 0, 0, $dstX, $dstY, $color); $pX = $pY = $pW = $pH = 0; if ($imgdata['width'] < $dstX && $imgdata['height'] < $dstY) { $pW = $imgdata['width']; $pH = $imgdata['height']; } else { if ($imgdata['width'] / $imgdata['height'] > $dstX / $dstY) { $pW = $dstX; $pH = round($dstX * $imgdata['height'] / $imgdata['width']); } else { $pH = $dstY; $pW = round($dstY * $imgdata['width'] / $imgdata['height']); } } $pX = round(($dstX - $pW) / 2); $pY = round(($dstY - $pH) / 2); $imagecopyre($thumb, $imgdata['source'], $pX, $pY, 0, 0, $pW, $pH, $imgdata['width'], $imgdata['height']); MakeImage($imgdata['type'], $thumb, $dstFile); imagedestroy($thumb); return 1; }