Net Php wrote:
> Hi, I am pretty lost..
> I am trying to create a php thumbnail with php without using any *sql
> database.this script was supposed to open a directory then read it
> resize the images without losing quality and displays it on screen.

> ok, here is what I am trying to do and its now working:

If it's working, then what's the question???


>    <?
> $dir = "imagestrips";
> if($abre = opendir($dir)) {
>
>
>      while($arq = readdir($abre))
>        { $filename = "imagestrips/" . $arq;
>        if(is_file($filename))
> {
>    $neww = 100;
>    $newh = 100;
>    header("Content-type: image/jpeg");
>    $dst_img=imagecreate($neww, $newh);
>    $src_img=imagecreatefromjpeg($filename);
>
>
imagecopyresized($dst_img,$src_img,0,0,0,0,$neww,$newh,imagesx($src_img),ima
gesy($src_img));    imagejpeg($dst_img);
>
>
> }
>      }
>    }
>
>    closedir($abre);
>    ?>

It look to me, this can't work. You are sending one header, then a jpeg,
then a header, then a jpeg. Don't you get a broken image? The browser
expects a header, then one image.

You're resize script will have to look like this:

resize.php
<?
if ( !file_exists( $_GET['filename'] )
{
    header( 'HTTP/1.0 404 Not Found' );
    exit;
}
$new = imagecreate( 100, 100 );
$im = imagecreatefromjpeg( $_GET['filename'] );
if ( !$im )
{
    header( 'HTTP/1.0 404 Not Found' );
    exit;
}
imagecopyresampled( $new, $im, 0, 0, 0, 0, 100, 100, imagesx( $im ),
imagey( $im ) );
imagejpeg( $new );
?>

You can invoke this with http://<domain>/resize.php?filename=img.jpg. You
can create a nice directory listing this way, just call the resize.php
script for every image on the page. Create the directory listing with the
opendir function you used above, but let it print a <img src='<resize script
url>' width='100' height='100'> instead of an image!

HTH
Erwin


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to