-5

我有这个代码可以生成一个缩略图,nw,我需要它来生成我两个...只是为了加倍功能,你能告诉我如何根据这个来做吗?

谢谢..

function tamano_nuevo_foto($im_or, $ancho_nv, $dir_nv) {
    $img   = imagecreatefromjpeg($im_or);
    $datos = getimagesize($im_or);
    $ancho = $datos[0];
    $alto  = $datos[1];

    if ($ancho > $ancho_nv) { //Si la imagen no lelga al máximo no la tocamos.
        $prop    = $alto / $ancho;
        $alto_nv = round($ancho_nv * $prop);
    } else {
        $ancho_nv = $ancho;
        $alto_nv  = $alto;
    }
    $im_nv    = imagecreatetruecolor($ancho_nv, $alto_nv);
    imagecopyresampled($im_nv, $img, 0, 0, 0, 0, $ancho_nv, $alto_nv, $ancho, $alto);
    imagejpeg($im_nv, $dir_nv);
    imagedestroy($im_nv);
}

if (!empty($_FILES)) {
    $tempFile   = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
    $targetPath = str_replace('//', '/', $targetPath);
    $targetFile = $targetPath . basename($_FILES['Filedata']['name'], '.' . $ext) . '_s.';
    tamano_nuevo_foto($tempFile, 120, $targetFile);
    echo str_replace($_SERVER['DOCUMENT_ROOT'], '', $targetFile);
}
4

2 回答 2

1

你能像下面这个例子那样调用这个函数两次吗?

if (!empty($_FILES)) {
    $tempFile   = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
    $targetPath = str_replace('//', '/', $targetPath);
    $targetFile = $targetPath . basename($_FILES['Filedata']['name'], '.' . $ext) . '_s.';
    $newTargetFile = // define whatever you want to call your second copy of thumbnail here
    tamano_nuevo_foto($tempFile, 120, $targetFile);
    tamano_nuevo_foto($tempFile, 120, $newTargetFile);
    echo str_replace($_SERVER['DOCUMENT_ROOT'], '', $targetFile);
}
于 2012-08-21T21:00:50.157 回答
0

只需调用该函数两次,或复制文件copy()

于 2012-08-21T20:59:39.023 回答