glenelkins Posted October 11, 2009 Share Posted October 11, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/177300-imagejpeg-outputs-url-rather-than-image/ Share on other sites More sharing options...
.josh Posted October 11, 2009 Share Posted October 11, 2009 what do you mean by "shows the current URL" ? do you mean that it is echoing out the url on the screen, or showing a blank page? In what context are you trying to use imagejpeg? Are you outputting something before it? Quote Link to comment https://forums.phpfreaks.com/topic/177300-imagejpeg-outputs-url-rather-than-image/#findComment-934923 Share on other sites More sharing options...
glenelkins Posted October 11, 2009 Author Share Posted October 11, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/177300-imagejpeg-outputs-url-rather-than-image/#findComment-935013 Share on other sites More sharing options...
glenelkins Posted October 11, 2009 Author Share Posted October 11, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/177300-imagejpeg-outputs-url-rather-than-image/#findComment-935014 Share on other sites More sharing options...
.josh Posted October 11, 2009 Share Posted October 11, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/177300-imagejpeg-outputs-url-rather-than-image/#findComment-935022 Share on other sites More sharing options...
glenelkins Posted October 11, 2009 Author Share Posted October 11, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/177300-imagejpeg-outputs-url-rather-than-image/#findComment-935036 Share on other sites More sharing options...
Dorky Posted October 11, 2009 Share Posted October 11, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/177300-imagejpeg-outputs-url-rather-than-image/#findComment-935045 Share on other sites More sharing options...
.josh Posted October 11, 2009 Share Posted October 11, 2009 yeah...for profile avatars you shouldn't really be resizing it every single page load...you should have it permanently resizing when the user uploads it in the first place. Quote Link to comment https://forums.phpfreaks.com/topic/177300-imagejpeg-outputs-url-rather-than-image/#findComment-935050 Share on other sites More sharing options...
Dorky Posted October 11, 2009 Share Posted October 11, 2009 crayon, your sig rocks dude Quote Link to comment https://forums.phpfreaks.com/topic/177300-imagejpeg-outputs-url-rather-than-image/#findComment-935060 Share on other sites More sharing options...
.josh Posted October 11, 2009 Share Posted October 11, 2009 crayon, your sig rocks dude let me tell you, ever since i made this thing, i have to beat the ladies off with a stick to keep them away from me, fuckin' throwin' themselves at me and shit. Quote Link to comment https://forums.phpfreaks.com/topic/177300-imagejpeg-outputs-url-rather-than-image/#findComment-935084 Share on other sites More sharing options...
glenelkins Posted October 12, 2009 Author Share Posted October 12, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/177300-imagejpeg-outputs-url-rather-than-image/#findComment-935321 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.