473,399 Members | 2,159 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,399 software developers and data experts.

i cannot save resized images

I am missing something elementary I think. I am trying to batch resize
the contents of a directory, using imagecreatefromjpg() etc.

I have tried many scripts and I can only seem to corrupt the jpg. My
latest script is this...

<?php
// The file
$filename = '6.jpg';

// Set a maximum height and width
$width = 10;
$height = 10;

// Content type
header('Content-type: image/jpeg');
//header("Content-Disposition: attachment; filename=6.jpg");

// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);

if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}

// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height,
$width_orig, $height_orig);

// Output
imagejpeg($image_p, $filename, 100);
?>

I am testing it on a single file, but it destroys the image. Does
imagejpeg write the new file in the current directory ? Or do I need to
do an fputs() ?

Thank you for any comments

Oct 25 '05 #1
1 1622
> I am testing it on a single file, but it destroys the image. Does
imagejpeg write the new file in the current directory ? Or do I need to
do an fputs() ?


Close, it is actually the current working directory. So if this was
done via include it will be in that path. Also what I suggest doing is
checking what the program is doing. My thought is that you have a
notice or warning being generated and that is causing the corruption of
the image, if it is being generated at all.

Try just letting it output to the browser without a header. You should
be able to see more details that way. Also turn your error reporting to
E_ALL via error_reporting(E_ALL); at the beginning of the script.

--
Mike Willbanks
Zend Certified Engineer
http://www.digitalstruct.com
Oct 25 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dag Eilertsen | last post by:
The script below resizes images into two different sizes. My problem is that the quality of the resized images is poor. Any idea how to improve my script? The users are only uploading jpg's. ...
6
by: Christopher Brandsdal | last post by:
Hi! I get an error when I run my code Is there any other way to get te information from my form? Heres the error I get and the code beneath. Line 120 is market with ''''''''''''Line...
6
by: Neo Geshel | last post by:
Greetings. I am making an admin interface, which allows me to upload photos to an access DB. The admin interface also needs to display the uploaded photos, but only needs to show them at a...
1
by: Hardy Wang | last post by:
Hi, I found a piece of code to add drop shadow to a photo like below, after I save the image, it is actually a BMP file even though I specify a JPG file extension (see...
1
by: liuliuliu | last post by:
hi -- sorry if this is trivial -- but how do you make a screenshot of a pygame display? i have a surface which is basically the entire visible screen -- how do you write this surface as an image...
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
3
by: Jankie | last post by:
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...
1
by: rflloyd | last post by:
I wish to create a property of a control which is an array of Images, such that I can add, edit and delete images in the VS2005 property window. I've created the property as: private Image...
4
by: Anna97 | last post by:
Hi, I guess I've built my site sort of strangely: The images are in the html (using tables), but the text is all in css positioned using coordinates (hovering over the images). I need my page...
2
jamesd0142
by: jamesd0142 | last post by:
Private Sub SaveResized() Dim bm As New Bitmap(PictureBox1.Image) Dim myX As Integer Dim myY As Integer myX = 640
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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
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
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...

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.