skewed up images

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

 



Hey,
Below the code code I am using, but before you see it let me try to explain
it a bit to you.

Basically I first check to see if a certain image has a bigger width, bigger
height or they are
equal, according to that I call the correct function.

I point the script to a image file (.jpg) then the script resizes the pic to
120pix while keeping the
pic proportionate.

in the beginning if the height is more, then its resizing perfectly...but if
the width is more I want to
cut out 90pix from the middle of the pic...instead its giving me a skewed
image as you can see from
here:
http://www.instantclub.com/skew.jpg

(I have also drawn a red rectangle on the original for where it was supposed
to cut)

*****************************
** And heres the code I am using: **
*****************************
<?php
function prop_thumb_height($filename)
{
header('Content-type: image/jpeg');
list($width_orig, $height_orig) =
getimagesize($profile_pics_path.strtolower($filename));
//echo $_SERVER['DOCUMENT_ROOT'].$profile_pics_path.$filename;
$width = 90;
$scale_by = $width / $width_orig;
$height = floor($height_orig * $scale_by + 0.5);
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($profile_pics_path.strtolower($filename));
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height,
$width_orig, $height_orig);
imagejpeg($image_p,$profile_thumbs_path.$filename, 100);
return $height;
}

function prop_thumb_width($filename,$the_height)
{
$width = 90;$height = $the_height;

header('Content-type: image/jpeg');
list($width_orig, $height_orig) =
getimagesize($profile_pics_path.strtolower($filename));
if ($width && ($width_orig < $height_orig))
 {$width = ($height / $height_orig) * $width_orig;}
else {$height = ($width / $width_orig) * $height_orig;}

$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($profile_pics_path.strtolower($filename));
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height,
$width_orig, $height_orig);

imagejpeg($image_p,$full_path.$profile_thumbs_path.$filename,100);
return $width;
}

function CR_make_crop($filename)
 {
  $new = imagecreatetruecolor(90,120);
  $img = imagecreatefromjpeg ($profile_pics_path.strtolower($filename));
list($width_orig2, $height_orig2) =
getimagesize($profile_pics_path.strtolower($filename));
  imagecopyresized ($new, $img, 0, 0, 0, 0,
90,120,$width_orig2,$height_orig2);
     imagedestroy($img);
     return $new;
 }

function CR_make_crop2($cut_from_top,$filename)
 {
$new = imagecreatetruecolor(90,120);
  $img = imagecreatefromjpeg($profile_thumbs_path.$filename);
list($width_orig2, $height_orig2) =
getimagesize($profile_thumbs_path.$filename);
  imagecopyresized ($new, $img, 0, 0, 0, $cut_from_top,
90,120,$width_orig2,120);
     imagedestroy($img);
     return $new;
 }

/////// All functions on top

  $pic1_name="1UilXQSj2S5VV29L.jpg";

// #### Get image size
  list($the_image_width1, $the_image_height1) = getimagesize($pic1_name);

  if($the_image_height1 > $the_image_width1)
  {
  $make_prop_thumb_and_get_height=prop_thumb_height($pic1_name);
  $step1=$make_prop_thumb_and_get_height-120;
  $step2=round($step1 / 2);

  $im = CR_make_crop2($step2,$pic1_name);
  imagejpeg($im,strtolower($pic1_name),80);
  imagedestroy($im);
  header('Content-type: text/html');
  }
  elseif($the_image_height1 < $the_image_width1)
  {
  prop_thumb_width($pic1_name,$the_image_height1);
  $im = CR_make_crop($pic1_name);
  imagejpeg($im,strtolower($pic1_name),80);
  imagedestroy($im);
  header('Content-type: text/html');
  }
  else // Width and height are same
  {
   $im = CR_make_crop($pic1_name);
  imagejpeg($im,strtolower($pic1_name),80);
  imagedestroy($im);
  header('Content-type: text/html');
  }
?>



Any ideas? I know I screwed up somewhere in the function...but just cant
figure it out...

Thanks,
Ryan

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux