Redenumire/redimensionare/copiere ptr a afisa in PHP ??

Ai o întrebare legată de PHP? Incercăm să îi găsim soluţie. Sau poate doar vrei să publici un cod interesant.

Moderatori: Zamolxe, Moderatori

Avatar utilizator
maniac0man
PHPRomania Supporter
Mesaje: 13
Membru din: Vin Aug 31, 2007 9:30 pm

Redenumire/redimensionare/copiere ptr a afisa in PHP ??

Mesajde maniac0man » Sâm Sep 01, 2007 8:28 pm

Ma tot chinui de ceva vreme sa realizez un formular care sa dauge in baza de date shi sa afisheze pe site.

In momentul in care fac up-load la o anumita poza vreau ca scriptul sa`mi redenumeasca poza dupa id , s`o redimenzioneze, si cel mai important sa`mi copie "noua" poza (redimensionata shi redenumita ) intr`un anumit folder in cazul meu "pics/".

$max=0;
$idPoza="select * from sony";
$idPoza1=mysql_query($idPoza);
while($row= mysql_fetch_array($idPoza1))
{
if($row['id']>$max)
{
$max=$row['id'];
}
}

//Functia upload start
if ($_FILES['logo']['name']!= "")
{
$newimg1 = ''.$max.''.".jpg";
$adresaImagine= "pics/";
move_uploaded_file ( $_FILES['logo']['tmp_name'], $adresaImagine. $newimg1 );
header("location: index.php");


ce imi lipseshte ptr a face redimensiona, redenumi , shi copia poza in folderul pics ca dupa ce fac upload in folderul respectiv nu gasesc nimic!



Avatar utilizator
snowman
Senior Member
Mesaje: 362
Membru din: Sâm Dec 02, 2006 7:40 pm
Localitate: Hunedoara

Mesajde snowman » Dum Sep 02, 2007 1:49 am

imagecreatetruecolor,imagecopyresampled / rename / copy
toate le gasesti la www.php.net ...cauta niste exemple incarca sa refaci scriptul si zine ce nu merge.


aaa si inca cv nu mai crea 2 topic-uri pt acelasi subiect...fa unu si urmarestel
say what?...

alopia
Junior Member
Mesaje: 36
Membru din: Dum Sep 02, 2007 10:53 pm
Contact:

Mesajde alopia » Joi Sep 06, 2007 3:47 pm

Vezi daca poti folosi functia asta.
Codul il public under GPL or LGPL license. Adica free to use.

Cod: Selectaţi tot

/** Move uploaded image, check the image, resize the image, convert the image to jpg.
* Returns false on failure or true on success.
*
*/
function Move_UploadedImage($pOriginalFile,$pTempFile,$pFinalFile,$pMaxSize,$pResizeAlways,$pQuality=75)
{

    // Move uploaded file
    if ( !move_uploaded_file( $pOriginalFile, $pTempFile ) )
    {
        return false;
    }

    // Get image informations
    $tempResult = getimagesize($pTempFile);
    if ( $tempResult == false )
    {
        unlink($pTempFile);
        return false;
    }
    $tempSrcWidth   = $tempResult[0];
    $tempSrcHeight  = $tempResult[1];
    $tempSrcType    = $tempResult[2];

    // Load image from file
    if ( $tempSrcType == 2 )
    {

        // JPG
        $tempImgSrc = @imagecreatefromjpeg($pTempFile);

    } elseif ( $tempSrcType == 1 )
    {

        // GIF
        $tempImgSrc = @imagecreatefromgif($pTempFile);

    } elseif ( $tempSrcType == 3 )
    {

        // PNG
        $tempImgSrc = @imagecreatefrompng($pTempFile);

    } else
    {
        unlink($pTempFile);
        return false;
    }

    // Delete original file
    unlink($pTempFile);

    // Check
    if (!$tempImgSrc) return false;

    // See if we need to resize the image
    if ( $pResizeAlways || $tempSrcWidth > $pMaxSize || $tempSrcHeight > $pMaxSize )
    {

        // Compute image size
        if($tempSrcWidth > $tempSrcHeight)
        {
            $tempDiv  = $tempSrcWidth / $pMaxSize;
        } else
        {
            $tempDiv  = $tempSrcHeight / $pMaxSize;
        }

        $tempDestWidth  = $tempSrcWidth / $tempDiv;
        $tempDestHeight = $tempSrcHeight / $tempDiv;

        // Create destination image
        $tempImgDest = @imagecreatetruecolor($tempDestWidth,$tempDestHeight);
        if ( !$tempImgDest )
        {
            imagedestroy($tempImgSrc);
            return false;
        }

        // Copy source to destination
        if ( !imagecopyresampled($tempImgDest,$tempImgSrc,0,0,0,0,$tempDestWidth, $tempDestHeight,$tempSrcWidth,$tempSrcHeight) )
        {
            imagedestroy($tempImgSrc);
            imagedestroy($tempImgDest);
            return false;
        }

        // Save destination
        imagejpeg($tempImgDest,$pFinalFile,$pQuality);

        // Destroy destination
        imagedestroy($tempImgDest);

    } else
    {

        // Save
        imagejpeg($tempImgSrc,$pFinalFile,$pQuality);

    }
   
    // Destroy source
    imagedestroy($tempImgSrc);

    // OK
    return true;

}


Înapoi la “Cod PHP”

Cine este conectat

Utilizatori ce ce navighează pe acest forum: Niciun utilizator înregistrat și 30 vizitatori