473,804 Members | 2,296 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Image Resize script in php

57 New Member
Sir
i want to resize image. Following script working in my local server. But This coding doesn't work in php 2.6.0. please help me
Expand|Select|Wrap|Line Numbers
  1. <form action="<?php echo $_server['php-self'];  ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
  2.         <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
  3.         <button name="submit" type="submit" class="submitButton">Upload/Resize Image</button>
  4. </form>
  5. <?php
  6.         if(isset($_POST['submit'])){
  7.           if (isset ($_FILES["new_image"])){
  8.               $imagename = $_FILES["new_image"]["name"];
  9.               $source = $_FILES["new_image"]["tmp_name"];
  10.               $target = "images/".$imagename;
  11.               //$prefix = 'small_';
  12.               move_uploaded_file($source, $target);
  13.  
  14.               $imagepath = $imagename;
  15.               $save = "images/sml_" . $imagepath; //This is the new file you saving
  16.               $file = "images/" . $imagepath; //This is the original file
  17.  
  18.               list($width, $height) = getimagesize($file) ; 
  19.  
  20.               $modwidth = 150; 
  21.  
  22.               $diff = $width / $modwidth;
  23.  
  24.               $modheight = $height / $diff; 
  25.               $tn = imagecreatetruecolor($modwidth, $modheight) ; 
  26.               $image = imagecreatefromjpeg($file) ; 
  27.               imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
  28.  
  29.               imagejpeg($tn, $save, 100) ; 
  30.  
  31.               $save = "images/sml_" . $imagepath; //This is the new file you saving
  32.               $file = "images/" . $imagepath; //This is the original file
  33.  
  34.               list($width, $height) = getimagesize($file) ; 
  35.  
  36.               $modwidth = 80; 
  37.  
  38.               $diff = $width / $modwidth;
  39.  
  40.               $modheight = $height / $diff; 
  41.               $tn = imagecreatetruecolor($modwidth, $modheight) ; 
  42.               $image = imagecreatefromjpeg($file) ; 
  43.               imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
  44.  
  45.               imagejpeg($tn, $save, 100) ; 
  46.             echo "Large image: <img src='images/".$imagepath."'><br>"; 
  47.             echo "Thumbnail: <img src='images/sml_".$imagepath."'>"; 
  48.  
  49.           }
  50.         }
  51. ?>
  52.  
Jun 2 '08 #1
3 3200
Noorain
57 New Member
Sir
i want to resize image. Following script working in my local server. But This coding doesn't work in php 2.6.0. please help me

<form action="<?php echo $_server['php-self']; ?>" method="post" enctype="multip art/form-data" id="something" class="uniForm" >
<input name="new_image " id="new_image" size="30" type="file" class="fileUplo ad" />
<button name="submit" type="submit" class="submitBu tton">Upload/Resize Image</button>
</form>
<?php
if(isset($_POST['submit'])){
if (isset ($_FILES["new_image"])){
$imagename = $_FILES["new_image"]["name"];
$source = $_FILES["new_image"]["tmp_name"];
$target = "images/".$imagenam e;
//$prefix = 'small_';
move_uploaded_f ile($source, $target);

$imagepath = $imagename;
$save = "images/sml_" . $imagepath; //This is the new file you saving
$file = "images/" . $imagepath; //This is the original file

list($width, $height) = getimagesize($f ile) ;

$modwidth = 150;

$diff = $width / $modwidth;

$modheight = $height / $diff;
$tn = imagecreatetrue color($modwidth , $modheight) ;
$image = imagecreatefrom jpeg($file) ;
imagecopyresamp led($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;

imagejpeg($tn, $save, 100) ;

$save = "images/sml_" . $imagepath; //This is the new file you saving
$file = "images/" . $imagepath; //This is the original file

list($width, $height) = getimagesize($f ile) ;

$modwidth = 80;

$diff = $width / $modwidth;

$modheight = $height / $diff;
$tn = imagecreatetrue color($modwidth , $modheight) ;
$image = imagecreatefrom jpeg($file) ;
imagecopyresamp led($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;

imagejpeg($tn, $save, 100) ;
echo "Large image: <img src='images/".$imagepath."' ><br>";
echo "Thumbnail: <img src='images/sml_".$imagepat h."'>";

}
}
?>

Sir
This coding doesn't work in PHP Version 5.1.6 please help me............. .........
thanks
Jun 2 '08 #2
hsriat
1,654 Recognized Expert Top Contributor
The code as such works for me.

It seems like GD is not working on you server.
(link)
Jun 2 '08 #3
Atli
5,058 Recognized Expert Expert
Sir
This coding doesn't work in PHP Version 5.1.6 please help me............. .........
thanks
Hi.
Simply telling us that it doesn't work is of no use to us.

How is it supposed to be working?
How is it really working?
Are you getting any errors?

Have you tried to fix this yourself?
What did you do? Did it change anything?

Having said that, I would have to agree with Harpreet.
When a working code that is dealing with image manipulation fails on a new server, the GD extension is most likely just missing.

P.S.
Use [code] tags when posting code examples.
See the Posting Guidelines for more info on that.
Jun 2 '08 #4

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

Similar topics

8
4823
by: Chris Dewin | last post by:
Hi. I run a website for my band, and the other guys want an image gallery. I'm thinking it would be nice and easy, if we could just upload a jpg into a dir called "gallery/". When the client clicks the "gallery" link, a cgi script could search the gallery/ dir, and create thumbnails of any jpeg images that don't already have a thumbnail associated with them. The script could then generate a page of clickable thumbnails. A few questions:
1
1717
by: Ulf Schleth | last post by:
hi, since i switched from 4.3.11 to php 4.4.1, i do have problems with scripts which use the 'resize.php' class (see http://www.phpclasses.org/browse/file/4571.html ) with following error-messages: PHP Warning: imagejpeg(): Unable to access /www/www.bla.de/dbimages/image/60_kl.jpg in /www/www.bla.de/admin/resize.php on line 136
10
4165
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...
15
5371
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the path of the uploaded image, and resize it with the provided dimensions. My function is below. The current function is returning an error when run from the upload function: A generic error occurred in GDI+. Not sure what exactly that means. From what...
0
1916
by: Mattia | last post by:
************************************************** Manage image without exhausted memory ************************************************** Hi; I have a big problem. I must create a script that upload an image an then resize it, if width or height are more than 250px. Now, after upload an image (in this example I suppose that it's a JPEG image):
2
2370
by: Poppa Pimp | last post by:
ImageResizer.php Image Resizer PLEASE HELP The URL of the page this is on in my site is http://poppa-pimps-wallpapers.com//ImageResizer.php You can click on browse and get image,but when you upload image it will go to another page and says ]((unable to create emp directory)) Here is a site to be able to see script actually work http://tech.tailoredweb.com/image-editor-52/ and can be DL from there also. I am using FP 2003 and...
3
3940
by: kayahr | last post by:
Hi there, I have a strange problem in Internet Explorer (IE6 and IE7). I'm writing a JavaScript application which allows the user to edit a photo composition. So when the user selects a photo then a frame is drawn around it with resize and rotate buttons. Now it happened to me that I replaced these buttons (32x32) with larger images (48x48). The filenames were not changed, I only copied the new images over the old ones. Then I reloaded the...
8
9436
by: infoseekar | last post by:
Image Resize & Rotation Hi I have 2 scripts, one for Image rotation and other image resize and they both are working. Image resize scripts load the picture and resize it and Image rotation rotate the image by 90 deg. They are two differennt files i.e. resize.php and rotate.php. What I want to do is to combine both rotate.php & resize.php files, so when the script resized the image than it will call rotate script to rotate the...
14
3732
anfetienne
by: anfetienne | last post by:
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...
9
4027
by: neovantage | last post by:
Hey geeks, I am using a script PHP Thumbnailer which resize image at run time. But it is not working in my case as i have integrated that script by studying it's documentation. Here is the URL where i am using his script. My URL and here is the script code i am using in my application <img src="show_image.php?file=show_image.php?file=images%2Fproducts%2F1246358928.gif" /> and the how_image.php file has the following code
0
9714
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
9594
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
10599
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...
1
7635
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
6863
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
5531
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3832
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.