473,546 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Resize image problem

4 New Member
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($im ages)
{
// Retrieving path
$filename = $images;
// Set a maximum height and width
$width = 100;
$height = 100;

// Get new dimensions
list($width_ori g, $height_orig) = getimagesize($f ilename);

$ratio_orig = $width_orig/$height_orig;

if ($width/$height > $ratio_orig) {
$width = $height*$ratio_ orig;
} else {
$height = $width/$ratio_orig;
}

// Resample
$image_p = imagecreatetrue color($width, $height);
$image = imagecreatefrom jpeg($filename) ;
imagecopyresamp led($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.ph p\"><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 2223
cassbiz
202 New Member
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
evolozik
4 New Member
no i am not using Image Magick

i got the tutorial from this website:
http://www.php.net/manual/en/function.imagec opyresampled.ph p

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.ph p\"><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 Recognized Expert Specialist
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($imag e_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
evolozik
4 New Member
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($imag e_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.ph p\"><img src=resizeimage ($img) border=0></a>";
[/php]

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

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

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

if i put the code like this:


[PHP]
//some code

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

// Get new dimensions
list($width_ori g, $height_orig) = getimagesize($f ilename);

$ratio_orig = $width_orig/$height_orig;

if ($width/$height > $ratio_orig) {
$width = $height*$ratio_ orig;
} else {
$height = $width/$ratio_orig;
}

// Resample
$image_p = imagecreatetrue color($width, $height);
$image = imagecreatefrom jpeg($filename) ;
imagecopyresamp led($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

// Output
$new=imagejpeg( $image_p, null, 100);
}
$img=$newRow['picture'];
resizeimage($im g)
[/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 Recognized Expert Specialist
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($i mage_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
1839
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 either a full size image or an image with supporting detail. It's the same idea used on lots of Web sites that show thumbnails where you click on one and...
0
2301
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 there a way I can anti alias / smooth the resized image before saving? If myThumb.ContentLength > 0 Then Dim myThumbData(myThumb.ContentLength) As...
2
1971
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 before alignment).I want to do everything in dyanamic. please help me. urs.. Rams
3
3249
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 parent that holds my user control is resized, I resize my image so that it uses the maximum available space. Note: It takes about 2 seconds to...
2
1726
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 image is uploaded and store it in the database. My client now thinks the images are too small and needs to be resized. I can change the resize...
14
2769
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 they look bad. So what is the best way to resize an image. I'm not too concerned about size, but I guess I would like to compress it on the upload. ...
15
5311
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...
1
3761
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 imageviewer (desktop application) I can view the image. I believe there is something wrong with the maximum colors... This is what I have now... Image...
8
9383
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 &...
3
3568
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 little website: 1. Small: DOWNsize of original image to be used as a thumbnail. 2. Medium: DOWNsize of original image to be used as user...
0
7507
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, well explore What is ONU, What Is Router, ONU & Routers main...
0
7698
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. ...
0
7947
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...
1
5361
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...
0
3492
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...
0
3472
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1922
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
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...

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.