Re: Resizing an image

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

 



On Tue, 29 Mar 2011 03:21:48 +0300, Andre Polykanine wrote:

>[...]
>My questions are:
>1.  what  are the restrictions of ImageCopyResampled()? Can I make a jpg
>image  from  a jpg one, and a png image from a png one? And what about
>gif's?

Yes, or even a JPEG from a GIF, or a PNG from a JPEG, etc. 

But: imagecopyresampled works on image *resources*, which you create
either as "blank canvases" or by reading from files. In your case, you
want to create a resource from a file (JPEG, PNG, GIF etc.) and another
as a blank canvas into which you will copy the original image, resampled
(or resized). See the examples here:

http://au2.php.net/manual/en/function.imagecopyresampled.php

After the comment "// Resample" it:
* creates a new blank image resource to copy into, i.e. $dst_image
* creates an image by reading a file, i.e. $src_image
* copies with resampling, i.e. from $src_image to $dst_image

>2.  I  don't  need to output the image as the script output, I need to
>upload it as a file (replacing the uploaded larger file). Could I make
>it with fwrite and then copy it to the server? All of the examples give 
>header("image/jpeg")...

You can write the new image to a file using one of these:

http://au2.php.net/manual/en/function.imagepng.php
http://au2.php.net/manual/en/function.imagejpeg.php
http://au2.php.net/manual/en/function.imagegif.php


NB: see the following comments by tim (at) leethost (dot) com, regarding
performance of imagecopyresampled vs imagecopyresized:

http://au2.php.net/manual/en/function.imagecopyresampled.php#77679
http://au2.php.net/manual/en/function.imagecopyresampled.php#72606

Also check out ImageMagick, if your host provides it (or you can install
it):

http://au2.php.net/manual/en/book.imagick.php
-- 
Ross McKay, Toronto, NSW Australia
"Let the laddie play wi the knife - he'll learn"
- The Wee Book of Calvin

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux