ImageCopyResampled - (Windows Example - Total solution)
First lets look at how I setup apache and php:
Latest php-4.1.1-Win32.zip unpacked to "c:\PHP"
Copy "C:\PHP\php.ini-dist" to your Windows dir and edit its
sections as below:
; The root of the PHP pages, used only if nonempty.
; In below folder is my scale_pic.php example and index.php
doc_root = "c:/www/public_html"
; Directory in which the loadable extensions (modules) reside.
extension_dir = ./extensions
; without this above line PHP will maybe not find its extensions
;Windows Extensions
extension=php_gd.dll
; there are many extensions, just enable above for ImageCopyResampled to work
Apache (apache_1.3.22-win32-x86.exe) installed to
c:\Apache\ (C:\Apache\Apache\Apache.exe)
Under install:
Network: my.localhost
Server : localhost
email : local@host.com
Find below sections in "C:\Apache\Apache\conf\httpd.conf" and edit as below:
ServerRoot "C:/Apache/Apache"
ServerName localhost
DocumentRoot "C:/www/public_html"
<Directory "C:/www/public_html">
Restart your Apache Server. Apache and PHP should now be running fine.
Copy any pic (800x600 or larger) to your webfolder as "C:/www/public_html/pic.jpg"
Create following php-code, as "scale_pic.php".
Start your browser, and type "localhost/scale_pic.php"
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<?
$src_img = ImageCreateFromJPEG("pic.jpg");
$size = GetImageSize ("pic.jpg");
$src_width = $size[0];
$src_height = $size[1];
$dest_sizeformat = 50; // how wide your thumb will be, just change to any number
$dest_width = $dest_sizeformat; // width will always be the same
$dest_height = round($dest_sizeformat/($src_width/$src_height)); // height will keep aspect of thumb
$quality = 50;
echo $src_width ." ". $src_height . "<BR>";
$dst_img = imagecreatetruecolor($dest_width,$dest_height);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height);
imagejpeg($dst_img, "new_file.jpg", $quality);
imagedestroy($src_img);
imagedestroy($dst_img);
?>
<IMG SRC="new_file.jpg">
</BODY>
// Next step will be to make it as a function, so not only names like "pic.jpg" and "new_file.jpg" will do.