Jump to content

[SOLVED] Image Resizing Not Working


cmgmyr

Recommended Posts

Hey Guys,

This is my script that I use for image resizing. I have a client on php5 and now i'm just getting those little red x's. He does have GD library and it is running. What do I need to change in order for it to work?

 

<?php

   header("Content-type: image/jpeg");
   $source = imagecreatefromjpeg($src);
   $orig_w=imagesx($source);
   $orig_h=imagesy($source);
   
   //See if there is a different height and width
   
   if(!$_GET['wmax']){
   		$wmax=100;
   }
   if(!$_GET['hmax']){
   		$hmax=100;
   }
   $quality=90;
   $bgcol=000000;
   
   if ($orig_w>$wmax || $orig_h>$hmax)
   {
       $thumb_w=$wmax;
       $thumb_h=$hmax;
       if ($thumb_w/$orig_w*$orig_h>$thumb_h) 
           $thumb_w=round($thumb_h*$orig_w/$orig_h); 
       else 
           $thumb_h=round($thumb_w*$orig_h/$orig_w);
   } else
   {
       $thumb_w=$orig_w;
       $thumb_h=$orig_h;
   }
   if (!@$bgcol)
   {
       $thumb=imagecreatetruecolor($thumb_w,$thumb_h);
       imagecopyresampled($thumb,$source,
                           0,0,0,0,$thumb_w,$thumb_h,$orig_w,$orig_h);
   }
   else
   {
       $thumb=imagecreatetruecolor($wmax,$hmax);
       imagefilledrectangle($thumb,0,0,$wmax-1,$hmax-1,intval($bgcol,16));
       imagecopyresampled($thumb,$source,
                           round(($wmax-$thumb_w)/2),round(($hmax-$thumb_h)/2),
                           0,0,$thumb_w,$thumb_h,$orig_w,$orig_h);
   }
   if (!@$quality) $quality=90;
   imagejpeg($thumb,"",$quality);
   imagedestroy($thumb);
?> 

 

Thanks,

-Chris

Link to comment
https://forums.phpfreaks.com/topic/46014-solved-image-resizing-not-working/
Share on other sites

Works fine!

 

test.php?scr=test.jpg

<?php
   header("Content-type: image/jpeg");
   $source = imagecreatefromjpeg($_GET['scr']); //<--updated
   $orig_w=imagesx($source);
   $orig_h=imagesy($source);
   
   //See if there is a different height and width
   
   if(!$_GET['wmax']){
   		$wmax=100;
   }
   if(!$_GET['hmax']){
   		$hmax=100;
   }
   $quality=90;
   $bgcol=000000;
   
   if ($orig_w>$wmax || $orig_h>$hmax)
   {
       $thumb_w=$wmax;
       $thumb_h=$hmax;
       if ($thumb_w/$orig_w*$orig_h>$thumb_h) 
           $thumb_w=round($thumb_h*$orig_w/$orig_h); 
       else 
           $thumb_h=round($thumb_w*$orig_h/$orig_w);
   } else
   {
       $thumb_w=$orig_w;
       $thumb_h=$orig_h;
   }
   if (!@$bgcol)
   {
       $thumb=imagecreatetruecolor($thumb_w,$thumb_h);
       imagecopyresampled($thumb,$source,
                           0,0,0,0,$thumb_w,$thumb_h,$orig_w,$orig_h);
   }
   else
   {
       $thumb=imagecreatetruecolor($wmax,$hmax);
       imagefilledrectangle($thumb,0,0,$wmax-1,$hmax-1,intval($bgcol,16));
       imagecopyresampled($thumb,$source,
                           round(($wmax-$thumb_w)/2),round(($hmax-$thumb_h)/2),
                           0,0,$thumb_w,$thumb_h,$orig_w,$orig_h);
   }
   if (!@$quality) $quality=90;
   imagejpeg($thumb,"",$quality);
   imagedestroy($thumb);
?> 

 

 

NOTE THE CHANGE $source = imagecreatefromjpeg($_GET['scr']);

the path to the image is

http://rainbowjewelersinc.com/new/thumb.php?src=images/cms_images/6iuf5uxcbheczb0z.jpg&wmax=500&hmax=500

 

is the code you are using

$source = imagecreatefromjpeg($_GET['scr']); //<--updated

 

or

 

$source = imagecreatefromjpeg($src);

test the script from.

 

Works fine!

 

test.php?scr=test.jpg

<?php
   header("Content-type: image/jpeg");
   $source = imagecreatefromjpeg($_GET['scr']); //<--updated
   $orig_w=imagesx($source);
   $orig_h=imagesy($source);
   
   //See if there is a different height and width
   
   if(!$_GET['wmax']){
   		$wmax=100;
   }
   if(!$_GET['hmax']){
   		$hmax=100;
   }
   $quality=90;
   $bgcol=000000;
   
   if ($orig_w>$wmax || $orig_h>$hmax)
   {
       $thumb_w=$wmax;
       $thumb_h=$hmax;
       if ($thumb_w/$orig_w*$orig_h>$thumb_h) 
           $thumb_w=round($thumb_h*$orig_w/$orig_h); 
       else 
           $thumb_h=round($thumb_w*$orig_h/$orig_w);
   } else
   {
       $thumb_w=$orig_w;
       $thumb_h=$orig_h;
   }
   if (!@$bgcol)
   {
       $thumb=imagecreatetruecolor($thumb_w,$thumb_h);
       imagecopyresampled($thumb,$source,
                           0,0,0,0,$thumb_w,$thumb_h,$orig_w,$orig_h);
   }
   else
   {
       $thumb=imagecreatetruecolor($wmax,$hmax);
       imagefilledrectangle($thumb,0,0,$wmax-1,$hmax-1,intval($bgcol,16));
       imagecopyresampled($thumb,$source,
                           round(($wmax-$thumb_w)/2),round(($hmax-$thumb_h)/2),
                           0,0,$thumb_w,$thumb_h,$orig_w,$orig_h);
   }
   if (!@$quality) $quality=90;
   imagejpeg($thumb,"",$quality);
   imagedestroy($thumb);
?> 

 

 

NOTE THE CHANGE $source = imagecreatefromjpeg($_GET['scr']);

oooow something wired

 

i linked my test script to your page

 

this WORKED

TEST.php?scr=http://rainbowjewelersinc.com/new/images/top.jpg

 

This FAILED

TEST.php?scr=http://rainbowjewelersinc.com/new/images/cms_images/6iuf5uxcbheczb0z.jpg

 

error Allowed memory size of 16777216 bytes exhausted

on this line

  $source = imagecreatefromjpeg($_GET['scr']);

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.