473,396 Members | 1,849 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,396 software developers and data experts.

Resize image problem

hi everyone
i need some help please
i am using PHP5 and i used a tutorial and when i copied the code for Resampling an image proportionally, it worked perfectly
but when i added it in my page it displayed a lot of "JFIF<y&<ߗ׏" characters

here is what i did:
[PHP]

//some code

function resizeimage($images)
{
// Retrieving path
$filename = $images;
// Set a maximum height and width
$width = 100;
$height = 100;

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

$ratio_orig = $width_orig/$height_orig;

if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_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
$new=imagejpeg($image_p, null, 100);
}

[/PHP]


then after some other code, i wrote:

[PHP]
$img=$newRow['picture'];
echo "<a href=\"test1.php\"><img src=resizeimage($img) border=0></a>";
[/PHP]

$newRow['picture'] is the path of the image saved in the database

anyone has an idea of why it is not working properly?
Jan 4 '07 #1
6 2218
cassbiz
202 100+
Is your script using ImageMagick?

if so, is it properly installed. You stated that it worked perfectly then after your changes it messed up or after you tried to resize an image without making any changes?
Jan 4 '07 #2
no i am not using Image Magick

i got the tutorial from this website:
http://www.php.net/manual/en/function.imagecopyresampled.php

the only thing i changed is that i enclosed the code in a function and added the part below so that it retrieves the image and then it resize it using the function before display the picture in <img src...>

[php]
$img=$newRow['picture'];
echo "<a href=\"test1.php\"><img src=resizeimage($img) border=0></a>";
[/php]

i think there is something wrong with this part :
<img src=resizeimage($img) border=0>
but i can't figure out what is missing or what i have put have i shouldn't have
Jan 4 '07 #3
ronverdonk
4,258 Expert 4TB
This line in your code has not the wanted effect:[php]$new=imagejpeg($image_p, null, 100);[/php] because imagejpeg() does not return a value, but just displays it onto the screen.
If you do not want to display it right away but later, you must save it[php]$file_name="my_file.jpg";
imagejpeg($image_p, $file_name, 100);[/php]Then later in your script you can display the file using the <img> tag.

Ronald :cool:
Jan 4 '07 #4
This line in your code has not the wanted effect:[php]$new=imagejpeg($image_p, null, 100);[/php] because imagejpeg() does not return a value, but just displays it onto the screen.
If you do not want to display it right away but later, you must save it[php]$file_name="my_file.jpg";
imagejpeg($image_p, $file_name, 100);[/php]Then later in your script you can display the file using the <img> tag.

Ronald :cool:
i added this part because i want it to display the picture right away
[php]
$new=imagejpeg($image_p, null, 100);
return $new;
[/php]

i understood what is wrong
using the code below doesn't display the picture but is trying to display the "codes" of the picture
[php]
$img=$newRow['picture'];
echo "<a href=\"test1.php\"><img src=resizeimage($img) border=0></a>";
[/php]

so i change it to
[php]
$img=$newRow['picture'];
echo "<a href=\"test1.php\">resizeimage($img)</a>";
[/php]

and now it displays for example:
resizeimage(images/pic.jpg)

is there a way that i can display the picture and not the link?
Jan 4 '07 #5
hey Ronald
i figured out something

if i put the code like this:


[PHP]
//some code

function resizeimage($images)
{
// Retrieving path
$filename = $images;
// Set a maximum height and width
$width = 100;
$height = 100;

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

$ratio_orig = $width_orig/$height_orig;

if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_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
$new=imagejpeg($image_p, null, 100);
}
$img=$newRow['picture'];
resizeimage($img)
[/PHP]
in this way the picture appears
but when i insert something between the function's closing bracket and $img then the weird characters appear
what is wrong?
Jan 4 '07 #6
ronverdonk
4,258 Expert 4TB
Those are not 'weird' characters, they are the content of the image file.
The last line of the function must destroy the image storage, so you must add statement[php]imagedestroy($image_p);[/php] at the end of the function.

As I said before, the '$new' variable is empty because there is nothing returned. It displays it only and at the exact spot where you issue the imagejpeg() command, nothing else! So why don't you save it and later display it?

Do not just copy samples, but complete the entire tutorial and you'll know.

Ronald :cool:
Jan 4 '07 #7

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

Similar topics

2
by: Charles Packer | last post by:
From one of the online Javascript tutorials, I learned how to open a new window and set its size. I'm building a page that has several small photographs, and I want to let the viewer examine...
0
by: Jay | last post by:
Hi guys, trying to fix a problem with an image resize routine. The code posted below uploads and resizes a jpeg, probablem is, the outlook can look a bit bitty becuase of teh samller size...is...
2
by: rams.kakara | last post by:
hi, My page have background image,on that image have more images and text. My problem is whenever resize browser that images are not resized and also not moved correct place .(i.e look not like...
3
by: Z D | last post by:
Hello, BACKGROUND: ============== I've created a Windows User Control that contains an Image Control (among other controls). The user control handles the picture resize event. Whenever the...
2
by: J'son | last post by:
Guys, I have built an application for a client that allows people to list their products for sale along with a photo of the product. If the photo is too big, I currently resize it down when the...
14
by: Rudy | last post by:
Hello all! I been trying to get a handle with Images. I have learned alot from the fine people here. So, I also learned that thumbnail images look terrible taken from a digital cam. I know why...
15
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...
1
by: Arjen | last post by:
Hi, I want to resize an image on my server. I tried a lot of samples... but all the time it does resize and saves the images but I can not view the image insize a webbrowser. With an...
8
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...
3
by: =?Utf-8?B?UiBSZXllcw==?= | last post by:
Hi! This discussion may help other programmers get a better idea of how to save uploaded images through a website. Why? Well currently, I save 3 versions of every uploaded image on my own...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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
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 projectplanning, coding, testing,...

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.