For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > June 2004 > Re: [PHP-DB] Image Resize









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PHP-DB] Image Resize
Neil Smith [Mvp

2004-06-30, 8:56 am

Kenny - you will find there are no native PHP handlers for TIFF.

If you're on a unix system you'll be able to use the imagemagick function=20
'convert' at a command line to do this. Something like this I developed for=
=20
a client will work, you'll need to look up the passthru function in the PHP=
=20
manual. This is an advanced technique, I'm not planning on discussing it in=
=20
detail so you'll need to figure out how to get it to work on your own=20
system. Please don't mail me saying 'it doesn't work'.

$binpath is the path to the system binaries, often /usr/bin. You're using=20
the 'convert' command whlch you'll need to read up on in the imagemagick=20
documentation, there's no space to put it here as it's very extensive in=20
what image formats it can convert. PNG, PSD, GIF and other formats are also=
=20
available.

In this case, $image_handle->username was just a user object which I used=20
as part of the file name for the created file, as was $imgid. The file name=
=20
ends in .jpeg in this case, convert decides what to convert to by the file=
=20
extension of the created file name you give it.

passthru("$binpath/convert -quality 100 tiff:$filename=20
$temppath".$image_handle->username.$imgid."jpeg",$imageraw);
$i=3D0;
while (!=20
is_file("$imgdir/".$image_handle->username.$imgid."jpeg") &&=20
filesize("$temppath".$image_handle->username.$imgid."jpeg")=3D=3D0) {
// Wait 0.2s increments for image creation to complete (if system is slow)
$i++;
if ($i >=3D 25) { // 5 seconds elapsed, still no file=
created
break;
}
clearstatcache();
usleep(200000);
}

You'll need to check to see if the created file is available after a few=20
milliseconds as this is an out-of-band process, that is PHP can't know when=
=20
the convert has finished in the case of a very large TIFF, So it polls the=
=20
directory for the file becoming available. Clearstatcache is needed to=20
purge the cached directory information, otherwise the loop will lock out=20
assuming the file is never there. It breaks the loop at 5 seconds anyway if=
=20
a hang has occurred.

HTH
Neil

At 02:46 30/06/2004 +0000, you wrote:
>To: Kenny <kenny@cobramail.com>, php-db@lists.php.net
>Content-Type: text/plain; charset=3DISO-8859-1; format=3Dflowed
>Content-Transfer-Encoding: 8bit
>Subject: Re: [PHP-DB] Image Resize
>
>Kenny wrote:
>
>tiff is not good graficformat. The browsers aren=B4 t able to display=

this.=20
>Some browsers, f. e. IE
>are not able to display the PNG-format always properly. The best you take=

=20
>only jpg. The snipplet
>you send seams to work.
>
>Regards,



=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D
CaptionKit http://www.captionkit.com : Production tools
for accessible subtitled internet media, transcripts
and searchable video. Supports Real Player, Quicktime
and Windows Media Player.

VideoChat with friends online, get Freshly Toasted every
day at http://www.fresh-toast.net : NetMeeting solutions
for a connected world.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com