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
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']);

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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']);

Link to comment
Share on other sites

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']);

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.