Pyh.conf’25: a new PHP conference for the Russian-speaking community

Voting

: max(three, one)?
(Example: nine)

The Note You're Voting On

Kokesh
21 years ago
Here is the simple, but powerful script for creating thumbnails on the fly.
You can include the script
directly to www page - just put it in <img src= tag.
with width 150pix.
This resizer respects the ASPECT RATIO.
Here is the script:
<?php
// Use it this way: resize.php?pic=imageurl&width=width_in_pixels
// [email protected] 2004
header("Content-type: image/jpeg");
$im = imagecreatefromjpeg($pic);
$orange = imagecolorallocate($im, 220, 210, 60);
$px = (imagesx($im) - 7.5 * strlen($string)) / 2;

$old_x=imageSX($im);
$old_y=imageSY($im);

$new_w=(int)($width);
if ((
$new_w<=0) or ($new_w>$old_x)) {
$new_w=$old_x;
}

$new_h=($old_x*($new_w/$old_x));

if (
$old_x > $old_y) {
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);

}
if (
$old_x < $old_y) {
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if (
$old_x == $old_y) {
$thumb_w=$new_w;
$thumb_h=$new_h;
}
$thumb=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresized($thumb,$im,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);

imagejpeg($thumb,"",90);
imagedestroy($thumb);
?>

<< Back to user notes page

To Top