function docrop() { //header('Content-type: image/jpeg'); $tMap = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); $pic = $_POST['pFile']; $iPic = uploadpath($pic, '+iPATH'); list($width, $height, $type) = @getimagesize($iPic); $_width = $_POST['width']; $_height = $_POST['height']; $w = $_POST['w']; $h = $_POST['h']; $x = $_POST['x']; $y = $_POST['y']; if ($width == $w && $height == $h) { javascript::alert('源图小于或等于剪裁尺寸,不剪裁!', 'js:parent.iCMS.insert("' . $pic . '","' . $_POST['callback'] . '");'); } if ($width == $_width && $height == $_height) { //不对源图缩放 $_img = iUpload::imagecreate($tMap[$type], $iPic); $_Type = $_img['type']; } else { $img = iUpload::imagecreate($tMap[$type], $iPic); $_Type = $img['type']; if ($img['res']) { $thumb = imagecreatetruecolor($_width, $_height); imagecopyresampled($thumb, $img['res'], 0, 0, 0, 0, $_width, $_height, $width, $height); $_tmpfile = FS::path_join(iPATH, $iCMS->config['uploadfiledir']) . '/crop_tmp_' . time() . rand(1, 999999); iUpload::image($thumb, $_Type, $_tmpfile); $_tmpfile .= '.' . $_Type; $_img = iUpload::imagecreate($tMap[$type], $_tmpfile); FS::del($_tmpfile); } } if ($_img['res']) { $_thumb = imagecreatetruecolor($w, $h); imagecopyresampled($_thumb, $_img['res'], 0, 0, $x, $y, $w, $h, $w, $h); $thumbpath = substr($iPic, 0, strrpos($iPic, '/')) . "/thumb"; $picName = substr($iPic, 0, strrpos($iPic, '.')); $picName = substr($picName, strrpos($picName, '/')); $fileName = $thumbpath . $picName . '_' . $w . 'x' . $h; FS::mkdir($thumbpath); iUpload::image($_thumb, $_img['type'], $fileName); $fileName .= '.' . $_Type; javascript::dialog($pic . '<br />剪裁成功!', 'js:parent.iCMS.insert("' . uploadpath($fileName, '-iPATH') . '","' . $_POST['callback'] . '");parent.iCMS_WINDOW_' . iCMSKEY . '.close();'); } }
function docrop() { $pic = $_POST['pFile']; $iPic = FS::fp($pic, '+iPATH'); list($width, $height, $type) = @getimagesize($iPic); $_width = $_POST['width']; $_height = $_POST['height']; $w = $_POST['w']; $h = $_POST['h']; $x = $_POST['x']; $y = $_POST['y']; $ext = FS::getExt($pic); if ($width == $w && $height == $h) { javascript::alert('源图小于或等于剪裁尺寸,不剪裁!', 'js:parent.iCMS.insert("' . $pic . '","' . $_POST['callback'] . '");'); } $imgres = iUpload::imagecreate($type, $iPic); if ($width != $_width || $height != $_height) { //对源图缩放 $thumb = imagecreatetruecolor($_width, $_height); imagecopyresampled($thumb, $imgres, 0, 0, 0, 0, $_width, $_height, $width, $height); $_tmpfile = FS::path_join(iPATH, $this->iCMS->config['uploadfiledir']) . '/crop_tmp_' . time() . rand(1, 999999) . '.' . $ext; iUpload::image($thumb, $type, $_tmpfile); $imgres = iUpload::imagecreate($type, $_tmpfile); FS::del($_tmpfile); } if ($imgres) { $_thumb = imagecreatetruecolor($w, $h); imagecopyresampled($_thumb, $imgres, 0, 0, $x, $y, $w, $h, $w, $h); $thumbpath = substr($iPic, 0, strrpos($iPic, '/')) . "/thumb"; $picName = substr($iPic, 0, strrpos($iPic, '.')); $picName = substr($picName, strrpos($picName, '/')); $fileName = $thumbpath . $picName . '_' . $w . 'x' . $h . '.' . $ext; FS::mkdir($thumbpath); iUpload::image($_thumb, $type, $fileName); javascript::dialog($pic . '<br />剪裁成功!', 'js:parent.iCMS.insert("' . FS::fp($fileName, '-iPATH') . '","' . $_POST['callback'] . '");parent.iCMS_WINDOW_' . iCMSKEY . '.close();'); } }