Re: Help needed

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

 



if(($_FILES['photo']['tmp_name'] != '')){
// This is the temporary file created by PHP
$uploadedfile = $_FILES['photo']['tmp_name'];

// Create an Image from it so we can do the resize
$src = imagecreatefromjpeg($uploadedfile);

// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);

// For our purposes, I have resized the image to be
// 600 pixels wide, and maintain the original aspect
// ratio. This prevents the image from being "stretched"
// or "squashed". If you prefer some max width other than
// 600, simply change the $newwidth variable
$newwidth=535;
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);

// this line actually does the image resizing, copying from the original
// image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);


$extension = getExtension($_FILES['photo']['name']);
$extension = strtolower($extension);
// now write the resized image to disk. I have assumed that you want the
// resized, uploaded image file to reside in the ./images subdirectory.
$filename = "C:\Apache2.2\htdocs\PagesImages/". $_FILES['photo']['name'];
imagejpeg($tmp,$filename,100);

imagedestroy($src);
imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when
the request
// has completed.
}

On Thu, Feb 5, 2009 at 12:17 PM, Atkinson, Robert
<ratkinson@xxxxxxxxxxxxx>wrote:

>   This extract handles file resizing for uploaded images :-
>
> require($_SERVER["DOCUMENT_ROOT"] . "\\localpath.php");
> $SelectedAlbum = $_POST["Album"];
> $AlbumPath = $strLocalPath . "album\\" . $_POST["Album"] . "\\";
> $SourcePath = $AlbumPath . "Source\\";
> $DonePath = $AlbumPath . "Done\\";
> $ThumbsPath = $AlbumPath . "Thumbs\\";
> $NormalPath = $AlbumPath . "Normal\\";
>
> $chkFileExists = TRUE; // Check the Thumbs and Normal
> directories so existing files don't get overwritten
> $MoveFile = TRUE; // Move the file from the Source
> directory to Done
> $ShowFinalLargeFile = TRUE; // Show the large image file in the
> results table
>
> $handle = "";
> $file = "";
> $imagespec = "";
>
> $newHeight = 0;
> $newWidth = 0;
> $ratio = 0;
>
> $FileFound = FALSE;
>
> clearstatcache();
>
> $handle = opendir($SourcePath);
>
> echo("Reading files from " . $SourcePath . "<br><br>");
>
> ?>
>
> <table width="100%" border="1">
>
> <?
> while (false !== ($file = readdir($handle))) {
>
> if ($EndTime < time() ) {
> break;
> }
>
> $extension = pathinfo($file,PATHINFO_EXTENSION);
> $extension = StrToUpper($extension);
>
> if ($file != "." && $file != ".." && ($extension == "JPG" || $extension
> == "GIF")) {
> $FileFound = TRUE;
> echo ("<tr>");
> echo ("<td valign=top align=left width=20%>");
> echo ("File = '" . $file . "'<br>");
> $imagespec = $SourcePath . $file;
> list($width, $height, $type, $attr) = getimagesize($imagespec);
> $imagebytes = filesize($imagespec);
> echo ("Height = " . $height . "<br>Width = " . $width . "<br>Bytes =
> " . $imagebytes . "<br>");
> echo ("</td>");
>
> if (file_exists($ThumbsPath . $file) && $chkFileExists) {
> echo ("<td valign=top align=center><font color=red>File <font
> color=black><b>" . $file . "</b></font> already exists in the Thumbs
> directory - cannot convert</font><br><br>");
> echo ("<img src='/album/$SelectedAlbum/thumbs/" . $file .
> "'></td>\n"); }
> elseif (file_exists($NormalPath . $file) && $chkFileExists) {
> echo ("<td valign=top align=center><font color=red>File <font
> color=black><b>" . $file . "</b></font> already exists in the Normal
> directory - cannot convert</font><br><br>");
> echo ("</td>\n"); }
> else {
> echo ("<td valign=top align=left>");
>
> $newfile = $ThumbsPath . $file;
>
> // resize using height
> $ratio = 100 / $height;
>
> if ($extension == "JPG") {
> $sourceHandle = imageCreateFromJpeg($imagespec); }
> elseif ($extension == "GIF") {
> $sourceHandle = imageCreateFromGif($imagespec); }
> else {
> die("Could not match file type");
> }
>
> $newWidth = $width * $ratio;
> $newHeight = $height * $ratio;
>
> echo("Resized to :-<br>Height = $newHeight <br>Width =
> $newWidth <br>Ratio = $ratio<br><br>");
> // exit;
>
> $destinationHandle = imageCreateTrueColor($newWidth,
> $newHeight);
> imageCopyResized($destinationHandle, $sourceHandle, 0, 0, 0,
> 0, $newWidth, $newHeight, $width, $height);
>
> if ($extension == "JPG") {
> imagejpeg($destinationHandle, $newfile, 100); }
> else {
> imagegif($destinationHandle, $newfile);
> }
>
> echo ("<img src='/album/$SelectedAlbum/thumbs/" . $file .
> "'><br>\n");
> echo ("</td>");
>
> if ($width > $height) {
> // resize using width
> $ratio = 800 / $width;
> $newWidth = $width * $ratio;
> $newHeight = $height * $ratio;
>
> // Override the above if the final height is still
> too big
> if ($newHeight > 450) $ratio = 450 / $height;
> }
> else {
> // resize using height
> $ratio = 450 / $height;
> $newWidth = $width * $ratio;
> $newHeight = $height * $ratio;
>
> // Override the above if the final height is still
> too big
> if ($newWidth > 800) $ratio = 800 / $width;
> }
>
> if ($width > 800 or $height > 450) {
> $newfile = $NormalPath . $file;
>
> if ($extension == "JPG") {
> $sourceHandle =
> imageCreateFromJpeg($imagespec); }
> else {
> $sourceHandle =
> imageCreateFromGif($imagespec);
> }
>
> $newWidth = $width * $ratio;
> $newHeight = $height * $ratio;
> $destinationHandle = imageCreateTrueColor($newWidth,
> $newHeight);
> imageCopyResized($destinationHandle, $sourceHandle,
> 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
>
> if ($extension == "JPG") {
> imagejpeg($destinationHandle, $newfile, 100);
> }
> else {
> imagegif($destinationHandle, $newfile); }
> }
> else {
> copy($imagespec, $NormalPath.$file);
> }
>
> if ($MoveFile) rename($imagespec, $DonePath.$file);
> }
>
> echo ("<td valign=top align=left>");
> echo("Resized to :-<br>Height = $newHeight <br>Width = $newWidth
> <br>Ratio = $ratio<br><br>");
> if ($ShowFinalLargeFile) echo ("<img
> src='/album/$SelectedAlbum/normal/" . $file . "'><br>\n");
> echo ("</td>");
> echo ("</tr>");
> ob_flush();
> flush();
> }
> }
>
> closedir($handle);
>
> ?>
>
> </table>
>
> <?
>
> -----Original Message-----
> From: php-objects@xxxxxxxxxxxxxxx <php-objects%40yahoogroups.com> [mailto:
> php-objects@xxxxxxxxxxxxxxx <php-objects%40yahoogroups.com>] On
> Behalf Of Mohsin Jimmy
> Sent: 05 February 2009 10:05
> To: php-objects@xxxxxxxxxxxxxxx <php-objects%40yahoogroups.com>
> Subject:  Help needed
>
> Hi All,
>
> I need php script which re size the image according to aspect ration making
> the width fixed and height variable.
> Can you guys refer to any free script for such functionality.
>
> Thank you
>
> [Non-text portions of this message have been removed]
>
> ------------------------------------
>
> Are you looking for a PHP job? Join the PHP Professionals directory Now!
> http://www.phpclasses.org/professionals/Yahoo! Groups Links
>
>
> ***********************************************************************************
> Any opinions expressed in email are those of the individual and not
> necessarily those of the company. This email and any files transmitted with
> it are confidential and solely for the use of the intended recipient
> or entity to whom they are addressed. It may contain material protected by
> attorney-client privilege. If you are not the intended recipient, or a
> person responsible for delivering to the intended recipient, be advised that
> you have received this email in error and that any use is strictly
> prohibited.
>
> Random House Group + 44 (0) 20 7840 8400
> http://www.randomhouse.co.uk
> http://www.booksattransworld.co.uk
> http://www.kidsatrandomhouse.co.uk
> Generic email address - enquiries@xxxxxxxxxxxxxxxxx<enquiries%40randomhouse.co.uk>
>
> Name & Registered Office:
> THE RANDOM HOUSE GROUP LIMITED
> 20 VAUXHALL BRIDGE ROAD
> LONDON
> SW1V 2SA
> Random House Group Ltd is registered in the United Kingdom with company No.
> 00954009, VAT number 102838980
>
> ***********************************************************************************
>
>  
>



-- 
Kind Regards,
Mohammad Al-Naji


[Non-text portions of this message have been removed]


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux