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?
6 2223
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?
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
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:
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?
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?
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:
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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
|
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...
|
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...
| |
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.
...
|
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...
|
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...
|
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 &...
|
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...
|
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...
| |
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. ...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |