Jump to content

Recommended Posts

Hi

 

I have created a class called pimage which a function resizeAndDisplay()

 

the function is called in my view like this $user->resizeAndDisplay ( 130, 130 );

 

now when the image is created i want it to output to the browser. but when i do, it just shows the current URL rather than the image

 

header ( "Content-type: image/jpeg" );
imagejpeg ( $_imgHolder );

 

i knpow the resize works as iv tested it by saving to a file...

Link to comment
https://forums.phpfreaks.com/topic/177300-imagejpeg-outputs-url-rather-than-image/
Share on other sites

well the function that generates the resized image is called inside some html

 

for example it could be:

 

<html>
<body>

    <p>SOME RANDOM TEXT</p>

    <div id="imageHolder"><?= $user->resizeAndDisplay ( 150,150 ); ?></div>

</bod>
</html>

and yes it outputs the current url in the address bar on a white screen, without the resized image

 

the whole point is i want to place this function anywhere in the html to display the image, and i understand that changing the header could be causing the issue

 

what would the point be in generating an image on the fly if i cant display it where i want?

well there are different "levels" to generating an image "on-the-fly".  Typically you generate an image resource. imagejpeg outputs an image either to the browser or to a file.  When you output it directly to the browser, it requires the image header, since you are outputting a raw image.  If you want to be able to place it anywhere on your page, you're going to have to output it to a file and then use a regular html img tag pointing to that file.

well thats not really efficient ad the program in question is resizing a users profile avatar. so for example 2 or 3 people at the same time view the profile, the file will be written at the same time...causing possible conflicts

your var = $var for this example

 

echo "<img src='$var' />";

 

if it is the url without the http:// then add it

 

echo "<img src='http://$var' />";

 

but for sake of argument it is better to use the resize during img upload and if you need this for a gallery, say thumb and full size. upload to two dif folders. one for thumbs and one for full. this requires the server to only compute on the upload and not every single time someone hits the page.

well resizing on upload is a pain really. because the system uses different sizes all over the place and i would rather not have to take up unessential disk space for profile images considering users will be uploading photo albums as well.

 

Now i assume from your last example, that i should actually call the generation script through URL rather than a object->function call?? Which again to me seems a little silly but if it has to be done so be it.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.