473,606 Members | 2,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

resizing a image

anfetienne
424 Contributor
hi.....i have this script (below #1) that is linked to another php file SimpleImage.php (#2) im trying to get it to work on my uploaded images but it keeps coming up errors.....i haven't altered anything except for:

$image->load('picture. jpg');
$image->resize(546,403 );
$image->save('picture2 .jpg');

I put the variables i need in there within " " instead of ' ' and i always get a error message.....am i doing something or cant this be used to the scale i require


#1
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.    include('SimpleImage.php');
  3.    $image = new SimpleImage();
  4.    $image->load('picture.jpg');
  5.    $image->resize(546,403);
  6.    $image->save('picture2.jpg');
  7. ?>
  8.  
#2
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. /*
  3. * File: SimpleImage.php
  4. * Author: Simon Jarvis
  5. * Copyright: 2006 Simon Jarvis
  6. * Date: 08/11/06
  7. * Link: http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php
  8. * This program is free software; you can redistribute it and/or 
  9. * modify it under the terms of the GNU General Public License 
  10. * as published by the Free Software Foundation; either version 2 
  11. * of the License, or (at your option) any later version.
  12. * This program is distributed in the hope that it will be useful, 
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of 
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
  15. * GNU General Public License for more details: 
  16. * http://www.gnu.org/licenses/gpl.html
  17. *
  18. */
  19.  
  20. class SimpleImage {
  21.  
  22.    var $image;
  23.    var $image_type;
  24.  
  25.    function load($filename) {
  26.       $image_info = getimagesize($filename);
  27.       $this->image_type = $image_info[2];
  28.       if( $this->image_type == IMAGETYPE_JPEG ) {
  29.          $this->image = imagecreatefromjpeg($filename);
  30.       } elseif( $this->image_type == IMAGETYPE_GIF ) {
  31.          $this->image = imagecreatefromgif($filename);
  32.       } elseif( $this->image_type == IMAGETYPE_PNG ) {
  33.          $this->image = imagecreatefrompng($filename);
  34.       }
  35.    }
  36.    function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
  37.       if( $image_type == IMAGETYPE_JPEG ) {
  38.          imagejpeg($this->image,$filename,$compression);
  39.       } elseif( $image_type == IMAGETYPE_GIF ) {
  40.          imagegif($this->image,$filename);         
  41.       } elseif( $image_type == IMAGETYPE_PNG ) {
  42.          imagepng($this->image,$filename);
  43.       }   
  44.       if( $permissions != null) {
  45.          chmod($filename,$permissions);
  46.       }
  47.    }
  48.    function output($image_type=IMAGETYPE_JPEG) {
  49.       if( $image_type == IMAGETYPE_JPEG ) {
  50.          imagejpeg($this->image);
  51.       } elseif( $image_type == IMAGETYPE_GIF ) {
  52.          imagegif($this->image);         
  53.       } elseif( $image_type == IMAGETYPE_PNG ) {
  54.          imagepng($this->image);
  55.       }   
  56.    }
  57.    function getWidth() {
  58.       return imagesx($this->image);
  59.    }
  60.    function getHeight() {
  61.       return imagesy($this->image);
  62.    }
  63.    function resizeToHeight($height) {
  64.       $ratio = $height / $this->getHeight();
  65.       $width = $this->getWidth() * $ratio;
  66.       $this->resize($width,$height);
  67.    }
  68.    function resizeToWidth($width) {
  69.       $ratio = $width / $this->getWidth();
  70.       $height = $this->getheight() * $ratio;
  71.       $this->resize($width,$height);
  72.    }
  73.    function scale($scale) {
  74.       $width = $this->getWidth() * $scale/100;
  75.       $height = $this->getheight() * $scale/100; 
  76.       $this->resize($width,$height);
  77.    }
  78.    function resize($width,$height) {
  79.       $new_image = imagecreatetruecolor($width, $height);
  80.       imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
  81.       $this->image = $new_image;   
  82.    }      
  83. }
  84. ?>
  85.  
  86.  
  87.  
  88.  
Mar 7 '09 #1
14 3714
Markus
6,050 Recognized Expert Expert
The error is?
Mar 7 '09 #2
anfetienne
424 Contributor
well.....the error has stopped but it said that this was invalid

function getWidth() {
return imagesx($this->image);
}
function getHeight() {
return imagesy($this->image);

and it wasn't detecting the files i was pointing to with my variable....thi s is

$resizeM = "upload/imgtemp/m/$random_digit/$filename";

include('Simple Image.php');
$image = new SimpleImage();
$image->load("$resizeM ");
$image->resize(250,400 );
$image->save("$resizeM ");
Mar 7 '09 #3
anfetienne
424 Contributor
thats the changes ive made
Mar 7 '09 #4
hoopy
88 New Member
Looks like a problem with the path try:

Expand|Select|Wrap|Line Numbers
  1. echo $resizeM;
And see what it outputs.

Also where is that script in relation to the uploads/ directory?
Mar 8 '09 #5
Markus
6,050 Recognized Expert Expert
The error has now stopped? Is the image resizing working now then?
Mar 8 '09 #6
anfetienne
424 Contributor
no it isn't resizing but it isn't giving me any errors.....its weird.....when i echo $resizeM i get the full location to the images that need resizing.

i'm going to think abaout this one and post again soon
Mar 9 '09 #7
Markus
6,050 Recognized Expert Expert
Do you have error reporting on?

Nothing jumps out at me, but could you be uploading an image that isn't a JPEG, PNG or GIF?
Mar 9 '09 #8
anfetienne
424 Contributor
error reporting is on and i have a set of test jpeg's that i am using to upload.

it's strange how it comes up with no errors at all but doesnt resize anything. I can't seem to figure this out

would it be better or easier to try resize the images during the upload process?
Mar 10 '09 #9
anfetienne
424 Contributor
this is the coding i made to upload my files with.....can it be adapted to resize the images on upload?

Expand|Select|Wrap|Line Numbers
  1. <?
  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. $folderPath="upload/$random_digit/";
  19.          }
  20.       }
  21. ?>
  22.  
Mar 10 '09 #10

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

Similar topics

2
2687
by: Alex Hopson | last post by:
I'm using the code below to loop through some images and resize each image twice, once to create a thumbnail and once to create a small image. The page stops loading around the 38th image out of 40+. Not always the same place but it's either 38th or 39th image, which I find strange as it's not consistent. At first I thought it was a timeout problem so I added - set_time_limit(0); and ignore_user_abort (true); to prevent it timing out,...
2
11255
by: Clyde Ellul | last post by:
Hi there. I need to write a simple program that reads a GIF image from an input stream, resizes it, then writes it back to an output stream in the same format (GIF). (JPEG input/output is good too, but GIF is preferrable). JAI can do this sort of but can't write to GIF format. Also, it looks too complicated for what I need; I'm a bit in a hurry... Is there a simple way of doing what I want? Is there a free,
10
2311
by: riki | last post by:
Hi, i have a big problem...i'm using one jscript for resizing of all of my pics in popUp...in main html i'm having many little pics and clicking on them they open in popUp and resize to larger version of the same pic. now, it works fine and sometimes when i click on little one it doesn't resize well... this is the code: main.html
5
4723
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 of their product. For each image uploaded (max 500Kb), I'll be resizing it to create a small, medium and large version after which I'll discard the original. My worry is that as the site becomes more popular, the processor time spent resizing...
1
2119
by: Ron Vecchi | last post by:
I am using asp.net to upload an image and then perform resizing on it and saving the different sizes to file. The resized images were coming up and being displayed in the bowser fine but the image sizes are a lot bigger(in file size) than the actual image being uploaded. The actual image being uploaded was around 22000bytes The smaller resized image is 120000bytes Also on the web when the resized image is displayed it starts out with a...
10
4138
by: David W. Simmonds | last post by:
I have a DataList control that has an Image control in the ItemTemplate. I would like to resize the image that goes into that control. I have a series of jpg files that are full size, full resolution (ie. large). I have a database that contains references to the pictures. Currently I have to resize the jpgs manually, and then point the ImageUrl property at that jpg using databinding. This works fine. I would like to avoid the resizing step...
6
2258
by: tomasio | last post by:
Dear NG, years have passed and I am still more designer than programmer. I build a new version of my website which has a few nasty bugs, especially on my startpage: Resizing text brakes the dotted lines which I use as visual border on the left and right edge of the page layout and thus produces an unwanted white gap above the enlarged text. Viewing the page with IE shows this behaviour even without changing the font size.
8
3682
by: berkshire | last post by:
Hi, Anyone know of a script out there that can resize images and not sacrifice image quality? I've been using phpthumb (http://phpthumb.sourceforge.net/) but when compared to an image resized in photoshop it's products are not as good (yeah I upped the image quality and tried out some filters - no luck). Tutorials or scripts online preferred are preferred, but if you know of a way to change the settings on phpthumb to maintain the...
10
7054
by: mishrarajesh44 | last post by:
hii all, I am facing a problem currently.. i have a script for image uploading and resizing.. the image uploading takes place properly for every size images.. but, the resizing works for only small sized iamages.. for eg. resizing takes place for 70 kb sized images but fails for 600kb or more.. my code is below..
0
8015
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7951
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8439
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8430
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8305
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6770
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5966
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5465
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.