473,511 Members | 16,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

image resizing within a loop won't function properlly

anfetienne
424 Contributor
i have a file upload script and within it i use SimpleImage... its a image resizing function. When just used on it's on it works fine, and when i use it within a simple loop like the one below it works fine

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include('SimpleImage.php');
  3. $add= "images/test/Desert.jpg";
  4.  
  5. $details = array();
  6. $details = getimagesize($add);
  7. $imgWidth = $details[0];
  8. if ($imgWidth > 450){
  9.             $image = new SimpleImage();
  10.             $image->load("$add");
  11.             $image->resize(450,350);
  12.             $image->save("$add"); 
  13.  
  14.     echo '<img src="'.$add .'" alt="test"/>';
  15. } else {
  16. echo $details[1].'<br/>';
  17. echo $details[4].'<br/>';
  18. echo $details[3].'<br/>';
  19. }
  20. ?>
  21.  
but when i include it into my upload script in the correct position it wont work.

this is the original script i wrote

Expand|Select|Wrap|Line Numbers
  1. include('SimpleImage.php');
  2. while(list($key,$value) = each($_FILES['images']['name']))
  3.         {
  4.             if(!empty($value))
  5.             {
  6.                 $filename = $value;
  7.                     $filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line
  8.  
  9.                     $add = "upload/imgtemp/m/$random_digit/$filename";
  10.                     $tempFLDR = "upload/imgtemp/t/$random_digit/$filename";
  11.                        //echo $_FILES['images']['type'][$key];
  12.                  // echo "<br>";
  13.                     copy($_FILES['images']['tmp_name'][$key], $add);
  14.                     chmod("$add",0777);
  15.                     copy($_FILES['images']['tmp_name'][$key], $tempFLDR);
  16.                     chmod("$tempFLDR",0777);
  17.             }
  18. $image = new SimpleImage();
  19. $image->load("$add");
  20. $image->resize(535,400);
  21. $image->save("$add"); 
  22.  
  23. $image = new SimpleImage();
  24. $image->load("$tempFLDR");
  25. $image->resize(100,75);
  26. $image->save("$tempFLDR"); 
  27.         }
  28.  
and this is what i've changed it to... i've included the same loop as the 1st code in the post... i've placed it in the same position as the original within loops i've checked on a blank page to make sure it works but it keeps cutting the script short

Expand|Select|Wrap|Line Numbers
  1. include('SimpleImage.php');
  2. while(list($key,$value) = each($_FILES['images']['name']))
  3.         {
  4.             if(!empty($value))
  5.             {
  6.                 $filename = $value;
  7.                     $filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line
  8.  
  9.                     $add = "user/tmp/large/$eventID/$filename";
  10.                     $tempFLDR = "user/tmp/av/$eventID/$filename";
  11.                        //echo $_FILES['images']['type'][$key];
  12.                  // echo "<br>";
  13.                     copy($_FILES['images']['tmp_name'][$key], $add);
  14.                     chmod("$add",0777);
  15.                     copy($_FILES['images']['tmp_name'][$key], $tempFLDR);
  16.                     chmod("$tempFLDR",0777);
  17.  
  18.             }
  19.  
  20. $details = array();
  21. $details = getimagesize($add);
  22. $detailsWidth = details[0];
  23. $detailsHeight = details[1];
  24.  
  25.             if ($detailsWidth > $detailsHeight){
  26.             $image = new SimpleImage();
  27.             $image->load("$add");
  28.             $image->resize(450,350);
  29.             $image->save("$add"); 
  30.  
  31.             $image = new SimpleImage();
  32.             $image->load("$tempFLDR");
  33.             $image->resize(100,70);
  34.             $image->save("$tempFLDR"); 
  35.             } 
  36.             elseif ($detailsHeight > $detailsWidth) {
  37.             $image = new SimpleImage();
  38.             $image->load("$add");
  39.             $image->resize(240,350);
  40.             $image->save("$add"); 
  41.  
  42.             $image = new SimpleImage();
  43.             $image->load("$tempFLDR");
  44.             $image->resize(100,100);
  45.             $image->save("$tempFLDR"); 
  46.             }
  47.         }
  48.  
May 25 '10 #1
1 1597
anfetienne
424 Contributor
nevermind... my illness is taking my eyes away from me or making me a clutz... my problem was here

Expand|Select|Wrap|Line Numbers
  1. $details = array();
  2. $details = getimagesize($add);
  3. $detailsWidth = details[0];  // <--- i left the $ off the variable
  4. $detailsHeight = details[1]; // <--- i left the $ off the variable
May 25 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2847
by: Ruby Tuesday | last post by:
I have a section(185pixelsx 185pixels) in my web page to display an image that is stored in a directory. Using php, how do you resize so if: the image dimension is smaller(width and height is...
4
4907
by: Amir | last post by:
Hi, I'd like to know if it's possible to pass an image name (the IMG SRC attribute) from HREF element to a function that is activated by onClick event and creates a Web page. I have this HREF...
5
4720
by: Jim | last post by:
I've heard that resizing images through PHP (either GD2 or ImageMagick) is a processor intensive exercise. I'm setting up a site where users will be uploading up to 10 images along with the details...
3
3305
by: lofty00 | last post by:
hello, sorry about the repost - I've been posting to several groups and I've decided it's better to make a single repost to all of them rather than an extra post in each. I've been trying to...
1
5948
by: Geuis | last post by:
Hi, new to the group. I use the following code to resize images my users upload. They're either blurry or they're jaggy. Can someone recommend modifications or different code that will resize...
7
2118
by: aaronic | last post by:
This is in reference to my previos post but a completely different problem. Previous problem and code can be found here: http://www.thescripts.com/forum/thread563724.html When I run the...
0
2668
by: Boricua | last post by:
I'm using ASP.NET 2.0 I got an imagebutton at the end of my form as a submit button. When the user clicks it the button becomes disabled and continues with the postback. This is what I got, ib...
0
984
by: Keldair via DotNetMonster.com | last post by:
Hello all, I am working with some barcode images using a TTF (True Type Font). I know it is not the best method, but it is what I have available at the moment. I have everything working all up...
6
7044
by: barber.brad | last post by:
We are code crushing the width of images from 285px to 260 pix. However we aren't changing the height. we need a bit of javascript that can make that percentage change to the height as well. Can...
2
2338
by: spinow | last post by:
Hi there, My current project has a div with a table inside it. In this table I have a cell. In this cell images are loaded using a javascript function and the images are resized to fit the cell with...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7355
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7510
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5668
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1576
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
447
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.