You are here: Re: Locate an image file on the server, extract data, resize and then output new image - can this be done? « PHP Programming Language « IT news, forums, messages
Re: Locate an image file on the server, extract data, resize and then output new image - can this be done?

Posted by Krustov on 07/27/06 12:33

<comp.lang.php>
<bizt>
<26 Jul 2006 13:00:23 -0700>
<1153944023.139985.255030@h48g2000cwc.googlegroups.com>

> I have a PHP program on my webspace that I use to upload images. As the
> images are about 500KB each, I would like to create a preview thumbnail
> image with smaller image dimensions than the original.
>


$whatsupdoc="thumbs/image5.jpg";

$pass=1; $filename=$whatsupdoc;
if (!file_exists($filename)) {$pass=0;}

if ($pass==0)
{
$biggy="images/image5.jpg";
$whatsupdoc="thumbs/image5.jpg";
include('create_thumb.php');
}


$size=GetImageSize($whatsupdoc);

<img src=$whatsupdoc width=$size[0] height=$size[1] border=0>




The above code will only create a thumbnail if it doesnt already exist .

If the thumbnail does exist - then it will just display it .




create_thumb.php


<?php

$img_name=$biggy;
$new_name=$whatsupdoc;
$max_width=120;
$max_height=70;
$size=GetImageSize($img_name);
$width_ratio=($size[0] / $max_width);
$height_ratio=($size[1] / $max_height);

if($width_ratio >=$height_ratio)
{
$ratio = $width_ratio;
}
else
{
$ratio = $height_ratio;
}
$new_width=($size[0] / $ratio);
$new_height=($size[1] / $ratio);
$src_img=ImageCreateFromJPEG($img_name);
$thumb=ImageCreateTrueColor($new_width,$new_height);
ImageCopyResampled($thumb,$src_img,0,0,0,0,($new_width-1),($new_height-
1),$size[0],$size[1]);
ImageJPEG($thumb,$new_name);
ImageDestroy($src_img);
ImageDestroy($thumb);

?>





--
Encrypted email address
www.emailuser.co.uk/?name=KRUSTOV
Make a shorter url
www.vhit.co.uk

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация