PHP 8.5.0 Alpha 1 available for testing

Voting

: min(five, six)?
(Example: nine)

The Note You're Voting On

it at chmzap dot ru
16 years ago
If the script should resize and save thumb I use this simple code:

<?php
/**
* Make thumbs from JPEG, PNG, GIF source file
*
* $tmpname = $_FILES['source']['tmp_name'];
* $size - max width size
* $save_dir - destination folder
* $save_name - tnumb new name
*
* Author: LEDok - http://www.citadelavto.ru/
*/

function img_resize( $tmpname, $size, $save_dir, $save_name )
{
$save_dir .= ( substr($save_dir,-1) != "/") ? "/" : "";
$gis = GetImageSize($tmpname);
$type = $gis[2];
switch(
$type)
{
case
"1": $imorig = imagecreatefromgif($tmpname); break;
case
"2": $imorig = imagecreatefromjpeg($tmpname);break;
case
"3": $imorig = imagecreatefrompng($tmpname); break;
default:
$imorig = imagecreatefromjpeg($tmpname);
}

$x = imageSX($imorig);
$y = imageSY($imorig);
if(
$gis[0] <= $size)
{
$av = $x;
$ah = $y;
}
else
{
$yc = $y*1.3333333;
$d = $x>$yc?$x:$yc;
$c = $d>$size ? $size/$d : $size;
$av = $x*$c; //высота исходной картинки
$ah = $y*$c; //длина исходной картинки
}
$im = imagecreate($av, $ah);
$im = imagecreatetruecolor($av,$ah);
if (
imagecopyresampled($im,$imorig , 0,0,0,0,$av,$ah,$x,$y))
if (
imagejpeg($im, $save_dir.$save_name))
return
true;
else
return
false;
}

?>

And now how using this function fast

<?php
if ($_POST[pic])
{
$tmpname = $_FILES['pic']['tmp_name'];
@
img_resize( $tmpname , 600 , "../album" , "album_".$id.".jpg");
@
img_resize( $tmpname , 120 , "../album" , "album_".$id."_small.jpg");
@
img_resize( $tmpname , 60 , "../album" , "album_".$id."verysmall.jpg");
}
else
echo
"No Images uploaded via POST";
?>

<< Back to user notes page

To Top