0

我正在尝试实现 YUI 图像裁剪器。我对 Javascript 几乎一无所知——显然很难理解它是如何工作的。谁能指出我正确的方向,以便能够获取图像裁剪区域的坐标,以便我可以将这些传递给 PHP 脚本以在将图像保存到文件之前进行裁剪。到目前为止,我得到了我想要裁剪的图像以及我可以拖动并使用手柄来放大和缩小的裁剪区域:

<script>
// Create a YUI sandbox on your page.
YUI().use('node', 'event', function (Y) {
// The Node and Event modules are loaded and ready to use.

var imgCrop = new YAHOO.widget.ImageCropper('crop1',
 { 
           minHeight: 100,
           minWidth: 200,
           initHeight: 100,
           initWidth: 200
        });

        var cropArea = imgCrop.getCropCoords();

});
</script>

<?php

<img src='$approve' id='crop1' />

?>

任何提示和指针将不胜感激,因为使用 YUI 被证明是困难的。谢谢

4

1 回答 1

0

首先,您可以使用 PHP 裁剪图像,那么为什么还要麻烦您不熟悉的语言呢?

其次,您裁剪图像的目的是什么?缩略图?

这是一个您可能会从中受益的示例。这将创建原始图像的 100x100(调整大小和裁剪)缩略图。

if(preg_match('/[.](jpg)$/', $tfile)) {
    $image = imagecreatefromjpeg($ufile);
} else if (preg_match('/[.](gif)$/', $tfile)) {
    $image = imagecreatefromgif($ufile);
} else if (preg_match('/[.](png)$/', $tfile)) {
    $image = imagecreatefrompng($ufile);
}
$oldx = imagesx($image);
$oldy = imagesy($image);
if ($oldx > $oldy) {
    $offx = ($oldx-$oldy)/2;
    $offy = 0;
    $oldx = $oldy;
} elseif ($oldy > $oldx) {
    $offx = 0;
    $offy = ($oldy-$oldx)/2;
    $oldy = $oldx;
} else {
    $offx = 0;
    $offy = 0;
}
$newim = imagecreatetruecolor(100, 100);
imagecopyresampled($newim, $image, 0, 0, $offx, $offy, 100, 100, $oldx, $oldy);
于 2012-09-17T22:01:04.983 回答