php image creation for security +++

images php coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Fri Nov 12, 2010 8:35 pm

php image creation for security +++

Postby kumado » Fri Nov 12, 2010 9:00 pm

I am looking for help in creating a simple image for future security and other uses.

I have searched many sites and most do not seem to work partly because there is some much "extra" stuff with it.

page one has :

Code: Select all

<img src="createimg.php" />

and the createimg.php :

Code: Select all


$im = imagecreatefrompng("pix/bg1.png");

//Output PNG Image
header("Content-Type: image/png");

//Destroy the image to free memory

//End Output

If I try to open createimg.php it says :

The image “” cannot be displayed, because it contains errors.

If I comment out the header line, there is a lot of characters I would assume to be the PNG image.
( A small sample - you can see the PNG part of the file header .... )

Code: Select all

‰PNG  ��� IHDR���È���#���^¹Òˆ��‹IDATxœÍœÙsǝÇ{îÁ}  H𾩃¤(QÖe]¶bÇÎÆvœÊz“­ì>lmÕîCö!•ªì?ÚÚTå!Þlí‘8öÆGl˺%KÅS¤(^à}€ˆû`î}€DA$ T»ßÔüfÝ===3Ÿþõ¯E���¸rå A.\Hš·nÝ‚ èôéÓIóÞ½{YË[��6“¢··‚ öööäчBtðàÁ¤ùøñc‚“¦Ãဠ¨ºº�ðËß½÷Š\Ť �E±©©)iŠ¢ØÚÚš4»»»EQìììLšwîÜáÌ™3Ióò7WÇãV{ãûÊWݱk7në°ÝN¡«« ‚ ­¬úúú jkkKšÃÃõ´´$Íññq‚êêê’æÌÌ AIsvv�Ád9H Ë%°›öH<==Úccc‚ lµÆÇEQ<|øpÒìééEñèÑ£IóîÝ»‚ œ:u*i^¿~]ÅóçÏ?iœË—!zíµ×Ò¶Fww7A[Ym»‚ÛNzzšçùÚÚÚ¤900Àóü‘#G’æÍ›7yžß*÷믿�  Gu¸Fçüh‚Ó(°\ÿ �0ê$Þ £SåóßT1¬ðxÖ÷YwØ

Likewise with the header in place, the calling page has a broken image box.

With the header commented out, the page is blank.

if I add an alt tag to the <img src ....... alt="here"> I see the alt text in either instance, with or without the header included.

For some reason it does not like the header command. At least in this instance. I did find one example that creates a grid in code and places text on the grid image and it does show on the calling page.

Am I missing a library? Is my syntax completely off?
Is there a very basic example that could show just an image without anything else "unneeded" included?
Do I need a session established for use?
I am somewhat new to parts of PHP.

I am using the code on a Suse machine with an Apache server running and all code is in the htdocs folders with user:group permissions set viewed in a Firefox browser from localhost.

thanks in advanced for any help.


I also opened gd_info and have the following:

array(12) { ["GD Version"]=> string(27) "bundled (2.0.34 compatible)" ["FreeType Support"]=> bool(true) ["FreeType Linkage"]=> string(13) "with freetype" ["T1Lib Support"]=> bool(true) ["GIF Read Support"]=> bool(true) ["GIF Create Support"]=> bool(true) ["JPEG Support"]=> bool(true) ["PNG Support"]=> bool(true) ["WBMP Support"]=> bool(true) ["XPM Support"]=> bool(true) ["XBM Support"]=> bool(true) ["JIS-mapped Japanese Font Support"]=> bool(false) }

I made a function from the call and included the file/page in my calling page ( functions.php )

Code: Select all

function MakeImg ()
$im = imagecreatefrompng("pix/bg1.png");

//Output PNG Image

//Destroy the image to free memory

and tried to display as : <img src="<?php MakeImg() ?>" alt="there"/>
and the following is displayed on my page :

Code: Select all

<°é§� ÌÈ\d£j(¡²ìU¹ŠaÅÁ©¨/̝jQIˆü/ÜNÝAä‹Ì�� œàýøñãI3Þ]>ê÷_ôˆ�zãì!»Y‰ÀPxO0ü?ÿæîÎ×Ôd ï¾0›@­Þ`â|‡eyæa*¼_½zU„->M=…¯»–‡´VË.œ{’8¼3,§ë‘' ´¬,³*QÎÞaIa×ðFq‘ef1V]?sÔšz4KÒOÂûÇ]±·N–6Vh3ÀûçwægVÈNž8–<šÞûœúïŸ)«-Ódï­G:¾q†p2¸g¡ ï/ £uÒÍêŠbIßØæG×æ<D†Ä$Žà(¡¸lrÞôÇûÑáYªÚ¦þ›·kìfeöµ:wÄ"#áÁi*Ë„t4Ã/­EƦý¼�ªmXe©E²m™TI …·ûuo‰Î¾n;õï7,¬…¯¾>‹§© ÏoHtÌXV¨±kŠt0š5 'XxrE2¹ η«ÿò¢qdÆŠeu«ì&¥ ?wÄ,—`Æ‚›FLy—†cü·×ëÊ4çÚÍÙd%%ÑKÇ

which almost seems to be the image data minus the file header ( both sections are but a small sample of the whole )

again, for any help I would be grateful.

Return to “PHP coding => Images”

Who is online

Users browsing this forum: No registered users and 1 guest