Some problems related to generate antispam(captcha) in jpgraph - php

When I integrate this code into a html file, it shows nothing, but it works when it is separate with the other html code.
So, could any one kindly teach me how to add it to html code and compare the form input with $chars?
require_once "/jpgraph/jpgraph_antispam.php";//the location is correct!!
$spam = new AntiSpam();
// saved to $chars for later verification of correct entry
$chars = $spam->Rand(8);
$spam->Stroke() ;

jpgraph returns raw images, you cannot include them in with HTML markup.
instead include the captcha.php as an image in HTML
<img src="captcha.php" />

I struggled with this turned out we had forgotten to intall GD on our linux (Centos) server
yum install php-gd
It was required by the call to imagejpeg in jpgraph_antispam.php

Related

PEAR Graphviz: Generating Images

Having installed the PEAR GraphViz package I'm trying to follow the second answer on this page to create a JPEG of a graph. As test code, I have the following:
<?php
require_once 'Image/GraphViz.php';
$graph = new Image_GraphViz();
$graph->addNode('A');
$img = $graph->fetch('jpeg', 'dot');
print "IMG: " . $img;
I've also tried it using the $graph->image('jpeg', 'dot'); method. Both ways, it returns an empty string. When I change the format to something like SVG, it works, which makes me think that certain image generation libraries just aren't installed. But I have the regular (commandline) Graphviz tools installed and they generate images fine. What do I need to install to make this work so PHP can generate images itself?

How to add graph to website?

I'm a beginner here and need help. I have this code, which works and outputs a graph in my browser (if this is the only code in php file). I don't know how to add text below or above just like any other site. When I try, it returns my whole code in the browser. How do I go on about this?
<?php
// content="text/plain; charset=utf-8"
require_once ('jpgraph/src/jpgraph.php');
require_once ('jpgraph/src/jpgraph_line.php');
// Some data
$ydata = array(11,3,8,12,5,1,9,8,5,7);
// Create the graph. These two calls are always required
$graph = new Graph(350,250);
$graph->SetScale('textlin');
// Create the linear plot
$lineplot=new LinePlot($ydata);
$lineplot->SetColor('blue');
// Add the plot to the graph
$graph->Add($lineplot);
// Display the graph
$graph->Stroke();
?>
Thanks in advance!
What you need is quite simply:
<img src="graph.php">
Put that in a separate HTML file or PHP script. You cannot output the image and text in the same script / web page. It needs to be separated.
Don't worry about the .php extension for the image src= attribute. It will display despite the lack of .jpeg extension. (The Graph class already outputs the correct MIME type I assume.)
I'm a bit rusty on PHP, but I believe that all "require" are supposed to be made before any content is output. Otherwise, the normal HTML/XHTML syntax and formatting take precedence.
I haven't actually used this library, but I'm assuming the image is output directly to the browser. It's probably easiest to create a new HTML document (or whatever the rest of your site is powered by) and include this as an image, with the image's src being the name of this script.

help with inline images/mail with cron - php?

I've got mailings that need to be sended using cron. When I load the script manualy all works fine. With cron i get broken images.
to change the src of my img i used:
$body = eregi_replace("managersrc_logo","images/managers/acertainlogo.jpg",$body);
Because i thaught that it is importent to use absolute paths i also tried:
$body = eregi_replace("managersrc_logo","http://www.site.com/images/managers/acertainlogo.jpg",$body);
In that case i even do not see the images when i run the cronscript manualy. Nor the automated cron will display me the images.
When i check the source of the mail that is received i always see "cid:encryptedstuff" even if i use absolute paths? Why is that? I just want my absolute paths being printed in the src attribute of the img tag. Who changes my absolute path to cid: ? is it php, phpmailer or outlook itself?
Any help someone?
can you post a sample html before and after being replaced (but before being sent)? maybe it has additional characters that break the url, ie src="/managersrc_logo". Also, maybe your mailing program has an option to integrate the images inside the message and can't find them?
The problem was an older version of phpmailer. I updated to the new version and the images are displayed perfectly now!!

Showing php page as an image

is that possible to show whole php page as an image file like png or jpg ?
for example,
<img src="details.php?id=44">
just like a screenshot of the page.
Thx
<?
// details.php file
// {
// do stuff to create your image and store in $my_image
// }
header("Content-type: image/jpg");
echo $my_image;
?>
1) output the mime type in the header.
2) echo your binary data
easy!
Not in the way you're thinking. You can use the PHP ImageMagick library or the PHP GD Library to generate an image dynamically and output it, but in order to get screenshots of a page you'll really need an outside service.
it depends on what you want to show. if its html/js/css, it varies across browsers.
If its unicode text to be displayed as images, you can use GD library for the purpose
I think you are talking about taking screenshots of a url or webpage. You can you freely available like:
http://www.shrinktheweb.com/
http://picoshot.com/
There are many such freely available services. If you want to host such service on your own server. You will need to create a software which can open your browser and take screenshot of the url. Ther are some softwares available as well. I hope it helps.

PHP - getting a site's favicon and converting it to png if necessary

For any given site "example.domain.tld" or merely "domain.tld" I need to do the following in PHP:
If the site has a favicon, get it wherever it is
If it is not already a PNG, convert it to PNG
Save it to /favicons/example.domain.tld.png
If the site has no favicon, do nothing.
Any ideas? I'm being stumped by the unreliable fileformat and location of the favicons, but if at all possible I want to avoid downloading the entire source of the page with file_get_contents in order to find it in the headers. Also converting to png seems nontrivial.
Thanks,
Mala
As is typical, I found a passable solution shortly after asking the question - let google do the work for you:
http://www.google.com/s2/favicons?domain=URL
returns a 16x16 png
Found this: http://www.controlstyle.com/articles/programming/text/php-favicon/
I'm about to try it for my project and I'll report back and tell you if it works!
Cheers
Iain
As Iain Fraser said, the Favicon class from controlstyle.com doesn't works with all test case.
Basically, if provided, the <link> shortcut icon tag can contain different URL types :
full absolute URL : http://www.domain.com/images/fav.ico
absolute URL with relative scheme : //www.domain.com/images/fav.ico
absolute path : /images/fav.ico
relative URL : ../images/fav.ico
Furthermore, the web page can contain a <base href="..." /> attribute that changes how to deal with relative URL and absoute path...
So I've written a PHP class that works with all these cases.
First, it tries to get the favicon URL from the <link> attribute, and fallback to the default favicon URI (//www.domain.com/favicon.ico) in case of failure.
You can grab it on my website here : http://www.finalclap.com/faq/477-php-favicon-find-download or install it using composer : composer require vincepare/favicon-downloader.
How to use :
<?php
require 'FaviconDownloader.class.php';
$favicon = new FaviconDownloader('http://stackoverflow.com/questions/19503326/bug-with-chrome-tabs-create-in-a-loop');
if($favicon->icoExists){
echo "Favicon found : ".$favicon->icoUrl."\n";
// Saving favicon to file
$filename = 'favicon-'.time().'.'.$favicon->icoType;
file_put_contents($filename, $favicon->icoData);
echo "Saved to ".$filename."\n\n";
} else {
echo "No favicon for ".$favicon->url."\n\n";
}
?>
Coverting to PNG is not that hard.
I don't get the question entirely, is this fav icon on your site or on other sites? If on other sites, you will have to parse fetched HTML and then somehow load favicon.
If the favicon isn't located at /favicon.ico I guess you have to parse the HTML.
For the filetype detection, you can use this extension, which detects the filetype by using magic bytes.
You can convert to PNG by using the GD library, an example can be found here.
If your PHP install includes the GD library, you can convert an image to a PNG using the imagepng function.

Categories