创建两个缩略图,而不是基于代码创建一个缩略图


create two thumbnails instead of one based on code

我有这段代码,它会为我生成一个缩略图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);
}

你能像下面的例子一样只调用两次函数吗?

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);
}

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