anubis Posted October 23, 2006 Share Posted October 23, 2006 Well, I made a php script that will add text to an image. Anyways, I converted it to .png, wrote an .htaccess file for it and everytime I run it my computer wants to download it.Anyways, here's the .png (actually a php): <?$im = imagecreatefrompng("custom2.png");if(!$im){die("");}$string = $_GET['text']; $orange = imagecolorallocate($im, 255, 180, 0);imagestring($im, 2, 5, 5, $string, $orange);header("Content-type:image/png");imagepng($im);imagedestroy($im);?> and here's the .htaccess: <Files custom.png>ForceType application/x-httpd-php</Files> Any help is greatly appreciated.Anubis Link to comment Share on other sites More sharing options...
jhecht Posted October 23, 2006 Share Posted October 23, 2006 the .htaccess file in my book is over kill.you already have the content-type set, that should already just display the file as an image in your browser. i think the fact that you ForceType is used is making your computer want to download it because the server is telling the browser to.My suggestion is just to get rid of the .htaccess file and see what happens. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 23, 2006 Share Posted October 23, 2006 Right, you don't need it there, unless you want to be able to post links to a .png image and have PHP execute it.<img src="custom.php?text=adsfdsfsa"> Link to comment Share on other sites More sharing options...
anubis Posted October 23, 2006 Author Share Posted October 23, 2006 ok, I got rid of the htaccess, but it still wants to download it. I don't know why this is happening cause regular .png files work, but this one doesn't.EDIT: the main reason i'm trying this is because I want it to work on my IPB forums. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 23, 2006 Share Posted October 23, 2006 It might want more headers then just the content-type. Maybe content-disposition or something else is required as well. Link to comment Share on other sites More sharing options...
anubis Posted October 23, 2006 Author Share Posted October 23, 2006 what should I use for the Content-Disposition line?EDIT: just tried all the functions for Content=Disposition, and none worked. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 23, 2006 Share Posted October 23, 2006 I was confused, content-disposition is usually used when you are creating a download box. However, you can still specify inline:header("Content-Disposition: inline; filename=custom.png");If it's still not working, try it on another server with another browser. Link to comment Share on other sites More sharing options...
anubis Posted October 24, 2006 Author Share Posted October 24, 2006 Ok, i've tried a couple of different hosts, none of which it worked on, and I tried 3 different browsers, and 2 wanted to download it and the last (internet explorer) just wants to see the code. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 24, 2006 Share Posted October 24, 2006 That's strange. I doubt this will matter, but try putting a space after content-type and before image/png. Is the code you posted above still what you are using, or has it changed? Link to comment Share on other sites More sharing options...
anubis Posted October 24, 2006 Author Share Posted October 24, 2006 I already tried putting a space there, and i'll post my updated script: <?php$im = imagecreatefrompng("custom2.png");if(!$im){die("");}$string = $_GET['text']; $orange = imagecolorallocate($im, 255, 180, 0);imagestring($im, 2, 5, 5, $string, $orange);header("Content-type: image/png");header("Content-Disposition: inline; filename=custom.png");imagepng($im);imagedestroy($im);?> EDIT: now i'm getting The image “http://arkonfx.com/images/pins/custom.png” cannot be displayed, because it contains errors. Link to comment Share on other sites More sharing options...
jhecht Posted October 24, 2006 Share Posted October 24, 2006 Yeah im sorry i can't really help you, i can just offer a little bit of offhand insight on this now( i dont use PHP's image functions at all... never had to and probably never will need to).if im correct, imagepng displays the image, and imagedestroy does what its name says, maybe its possible the header for png's are different (i've heard many things about IE not liking PNG's at all, and their use and acceptance browser wide not being well), so if you could, change possibly to JPEG's. I have no idea what content-disposition does, but i thought the content type had to be capitolized (ie Content-Type), if im wrong then i done hit the shift key one too many times.Other than that, im sorry but i can't help you. Link to comment Share on other sites More sharing options...
Little Goat Posted October 25, 2006 Share Posted October 25, 2006 did you delete the .htaccess file? if so, you need to change the extension to .php instead of .png. Link to comment Share on other sites More sharing options...
shiftJIS Posted October 25, 2006 Share Posted October 25, 2006 Well, the standard way of programming is to make sure each part works. So change your code to .php extension and try this:Contents of 'custom.php' <?php$file = "template.png";$im = @imagecreatefrompng($file); if(!$im){ die("Image-file $file does not exist.");}$string = $_GET['text'];$orange = imagecolorallocate($im, 255, 180, 0);imagestring($im, 2, 5, 5, $string, $orange);header("Content-type: image/png");header("Content-Disposition: inline; filename=custom.png");imagepng($im);imagedestroy($im); ?> Make sure all that works. Then, if your server allows mod_rewrite, use this:add to .htaccess <IfModule mod_rewrite.c>RewriteEngine OnRewriteRule ^custom.png(/?)$ custom.php</IfModule> Then, in your html, you can use: <img src="custom.png?text=blahblah" alt="you better put alt text here" /> Link to comment Share on other sites More sharing options...
justsomeguy Posted October 25, 2006 Share Posted October 25, 2006 if im correct, imagepng displays the image, and imagedestroy does what its name says, maybe its possible the header for png's are different (i've heard many things about IE not liking PNG's at all, and their use and acceptance browser wide not being well), so if you could, change possibly to JPEG's. I have no idea what content-disposition does, but i thought the content type had to be capitolized (ie Content-Type), if im wrong then i done hit the shift key one too many times.About that, PNG images do not require any special headers, just the content-type. The content-disposition is pretty much there for posterity. Other then letting you say what the file name is, you can also use a content-disposition of attachment instead of inline to help force a download box. The only problem IE has with PNG images is that it does not display alpha transparency correctly (apparently, IE7 fixes that). Most images without transparency look fine in IE. Other then IE, PNGs are in wide use in modern browsers, the standard is around 10 years old now and is well-documented and includes examples. Here is a page for testing PNG transparency with your browser. IE6 gets it right 2 times out of 20.http://entropymine.com/jason/testbed/pngtrans/ Link to comment Share on other sites More sharing options...
anubis Posted October 25, 2006 Author Share Posted October 25, 2006 that's wierd, shift your idea didn't work. Link to comment Share on other sites More sharing options...
shiftJIS Posted October 26, 2006 Share Posted October 26, 2006 Not very helpful.Didn't work how? Which part? What happened? What's the browser output look like? I'm not psychic. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 26, 2006 Share Posted October 26, 2006 I forgot to mention that headers are case-insensitive, and I guess the white space before the value doesn't matter either (although, a single space is 'preferred'). Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now