All pastes #71741 Raw Edit

Miscellany

public text v1 · immutable
#71741 ·published 2006-06-26 02:29 UTC
rendered paste body
<?php
function image_constraints($img,$dimx,$dimy) {
$x = imagesx($img);
$y = imagesy($img);
$xorg = $x;
$yorg = $y;
$altered = false;
if($x > $dimx){
$ratio = ($dimx/$x);
$x = $ratio * $x;
$y = $ratio * $y;
$altered = true; }
if($y > $dimy) {
$ratio = ($dimy/$y);
$y = $ratio * $y;
$x = $ratio * $x;
$altered = true; }
if(!$altered) {
return $img; }
$dest = imagecreatetruecolor($x,$y);
imagecopyresized($dest,$img,0,0,0,0,$x,$y,$xorg,$yorg);
return $dest; }
?> 

<?php
$img = imagecreatefromjpeg('sassy03.jpg');
$img = image_constraints($img,100,100);
$img = imagejpeg($img);
return;
?>