RE: Generate thumbnails from MySql database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi all,

cause a lot of people are asking for a thumbnail script:

some explenation:

this script makes 2 new pics of a uploaded pic, 1 thumbnail and 1 bigger
picture (but the bigger one will all be of the same size.. it's better....

you also see this: if ($site=="who-r-u"){

this is because the sript is used on 2 servers , you can also see it like
this:

if ($site=="who-r-u"){  > you have to use this part if you have GD 1
compiled with pph
}else{ > this if you have gd2 compiled on your pc  so pic the right one and
trow away the rest!!!  but with gd2 the pics will be a lot better.

on http://www.nederlandmobiel.nl you can see how it is used!!

please don't mail me all back what the functions are doing, but go to
www.php.net and look them up

hope it helps you

-mark-



function image_create($image, $url, $name){

    $inputImg = ImageCreateFromJPEG($image);

    $srcX = imagesx($inputImg);
    $srcY = imagesy($inputImg);

    // image size thumbnail
    $dstY_1 = 45; // height (altijd hetzelfde)
    $maxX_1 = 60; // widthe (als plaatje is kleiner dan centreren)

    // image size big foto
    $dstY_2 = 210; // hoogte (altijd hetzelfde)
    $maxX_2 = 280; // breedte (als plaatje is kleiner dan centreren)

    $ratio_1 = ($srcY / $dstY_1);
    $dstX_1  = ($srcX / $ratio_1);

    $ratio_2 = ($srcY / $dstY_2);
    $dstX_2  = ($srcX / $ratio_2);

    if ($site=="who-r-u"){
      $outputImg_1 = ImageCreate($maxX_1, $dstY_1);
      $outputImg_2 = ImageCreate($maxX_2, $dstY_2);
    }else{
      $outputImg_1 = imagecreatetruecolor($maxX_1, $dstY_1);
      $outputImg_2 = imagecreatetruecolor($maxX_2, $dstY_2); 
    }
    
    imagefill($outputImg_1, 0, 0, ImageColorAllocate($outputImg_1, 255, 255,
255));
    imagefill($outputImg_2, 0, 0, ImageColorAllocate($outputImg_2, 255, 255,
255));
    
    if ($site=="who-r-u"){
      ImageCopyResized($outputImg_1, $inputImg,(($maxX_1 - $dstX_1) /
2),0,0,0,$dstX_1, $dstY_1, $srcX, $srcY);
      ImageCopyResized($outputImg_2, $inputImg,(($maxX_2 - $dstX_2) /
2),0,0,0,$dstX_2, $dstY_2, $srcX, $srcY);
    }else{
      imagecopyresampled($outputImg_1, $inputImg,(($maxX_1 - $dstX_1) /
2),0,0,0,$dstX_1, $dstY_1, $srcX, $srcY);
      imagecopyresampled($outputImg_2, $inputImg,(($maxX_2 - $dstX_2) /
2),0,0,0,$dstX_2, $dstY_2, $srcX, $srcY);
    }

    imagejpeg($outputImg_1, $url."thumbnails/$name");
    imagejpeg($outputImg_2, $url."$name");
}


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux