473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Save thumbernails and delete original images

58
Ok,I now realized that imagecopyresize does not actually resize original image for good,but just resizes the display.
I can live with that.
Can someone help me to get this piece of code save the created thumbernail instead of outputing the resized result on the fly to the browser ?
I want the created thumbernail saved in the same directory as the original uploaded image.Even better overwrites it and just keep the reduced version.

Expand|Select|Wrap|Line Numbers
  1. $imagepath = $uploaddir.$imageName;
  2.     list($width,$height)=getimagesize($imagepath); 
  3.      if($height > 480){  
  4.   $image = imagecreatefromjpeg($imagepath);
  5.           $newheight=480; 
  6.         $newwidth=($width/$height)*480;        
  7.         $thumb = imagecreatetruecolor($newwidth,$newheight);
  8. imagecopyresampled($thumb,$image,0,0,0,0,$newwidth,$newheight,$width,$height);  
  9.         imagejpeg($thumb,$image,100);     
  10.         imagedestroy($image); 
  11.         imagedestroy($thumb); 
  12.      }
  13. else if($width > 620){        
  14.         $image = imagecreatefromjpeg($imagepath);
  15.         $newwidth=620; 
  16.         $newheight=($height/$width)*620; 
  17.         $thumb =imagecreatetruecolor($newwidth,$newheight); 
  18.          imagecopyresampled($thumb,$image,0,0,0,0,$newwidth,$newheight,$width,$height); 
  19. header("Content-Type: image/jpeg");
  20.  
  21. imagejpeg($thumb,$image,100);     
  22.         imagedestroy($image); 
  23.         imagedestroy($thumb); 
  24.     }
  25. echo "<img src\"$imagepath\" height=\"$newheight\" width=\"$newwidth\" />";
  26.  
< Please use [code] tags when posting code! -Atli >
Jun 29 '07 #1
3 1762
kovik
1,044 Expert 1GB
imagejpeg only takes up to three parameters. The first parameter is the image resource, the second is the file to save it to, and the third is the quality. I don't think your $image variable is a filename. :-p
Jun 29 '07 #2
Jankie
58
$image is the path to a filename.It saves the original just not the thumbernail
Jun 30 '07 #3
kovik
1,044 Expert 1GB
$image is the path to a filename.It saves the original just not the thumbernail
No, that's what I'm trying to tell you. $image is NOT a filepath.

Expand|Select|Wrap|Line Numbers
  1. $image = imagecreatefromjpeg($imagepath);
See?
Jun 30 '07 #4

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

Similar topics

4
by: dan glenn | last post by:
(PHP4.3.4, GD2) How can I save a PNG using GD2 and insure that it saves as a palette-based (8-bit, 256-color) single-color transparancy?? Saving this way, I could be sure that an image loaded from...
4
by: GlobalBruce | last post by:
The global assembly cache on my development computer has duplicate native images of several System assemblies. For instance, the System assembly itself is present as two different native images, as...
3
by: GMane Python | last post by:
Hello All. I have a program that downloads 'gigabytes' of Axis NetCam photos per day. Right now, I set up the process to put the images into a queue, and every 30 or so seconds, 'pop' them from...
9
by: Mark Johnson | last post by:
How can you save all or a portion of the Grafics object to a Image/Bitmap ? I am try to save the Images from Cards.dll to a BitMap file. I can read in the Images to the Grafics, but when I try this...
5
by: Neil | last post by:
I am getting time-out errors when I try to perform a simple delete on a linked server. The command is: Delete From MyTable Where PKID=12345 I have tried executing this command directly from...
0
by: darrel | last post by:
The app I am writing can upload and save images and (hopefully) delete said images as well. The upload functions work just fine, and save the files where I want them. The delete function,...
3
by: | last post by:
Hello All I Use The Command Me.ImageList.Add(Image.FromFile(PATH)) To Loed Images To An ImangeList But The ImageList Dont Save The Images (Delete Them From The HD Or Change Their Path They WIll...
5
by: terrybell105 | last post by:
I downloaded Stephan's utility from his website but can't get it to work - or maybe I'm not driving it properly! The form works OK with the existing 3 "views" - I can switch between them and they...
3
by: neovantage | last post by:
Hey all, i have created image by mixing logo and the original image. It create image and show in the same window. I have done 3 steps for this. First i upload an image to my server by using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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...

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.