How to display graph from database values using php? - php

I want to create graph using php. I have tested jpgraph example. But it display error
like
> The image “http://localhost/test/jpgraphtest.php” cannot be displayed
> because it contains errors.
<?php
include('phpgraphlib.php');
$graph = new PHPGraphLib(500,350);
$data = array(12124, 5535, 43373, 22223, 90432, 23332, 15544, 24523,
32778, 38878, 28787, 33243, 34832, 32302);
$graph->addData($data);
$graph->setTitle('Widgets Produced');
$graph->setGradient('red', 'maroon');
$graph->createGraph();
?>

check this link I think its perfect.
http://pchart.sourceforge.net/
(also you should configure php to enable image creating).
In Windows, you'll include the GD2 DLL php_gd2.dll as an extension in php.ini. The GD1 DLL php_gd.dll was removed in PHP 4.3.2. Also note that the preferred truecolor image functions, such as imagecreatetruecolor(), require GD2.
check these links.
http://www.php.net/manual/en/image.requirements.php
http://www.php.net/manual/en/image.installation.php
http://www.php.net/manual/en/image.configuration.php
examples:

Related

php How to reduce file size using gd and upload to folder [duplicate]

I have a site with about 1500 JPEG images, and I want to compress them all. Going through the directories is not a problem, but I cannot seem to find a function that compresses a JPEG that is already on the server (I don't want to upload a new one), and replaces the old one.
Does PHP have a built in function for this? If not, how do I read the JPEG from the folder into the script?
Thanks.
you're not telling if you're using GD, so i assume this.
$img = imagecreatefromjpeg("myimage.jpg"); // load the image-to-be-saved
// 50 is quality; change from 0 (worst quality,smaller file) - 100 (best quality)
imagejpeg($img,"myimage_new.jpg",50);
unlink("myimage.jpg"); // remove the old image
I prefer using the IMagick extension for working with images. GD uses too much memory, especially for larger files. Here's a code snippet by Charles Hall in the PHP manual:
$img = new Imagick();
$img->readImage($src);
$img->setImageCompression(Imagick::COMPRESSION_JPEG);
$img->setImageCompressionQuality(90);
$img->stripImage();
$img->writeImage($dest);
$img->clean();
You will need to use the php gd library for that... Most servers have it installed by default. There are a lot of examples out there if you search for 'resize image php gd'.
For instance have a look at this page http://911-need-code-help.blogspot.nl/2008/10/resize-images-using-phpgd-library.html
The solution provided by vlzvl works well. However, using this solution, you can also overwrite an image by changing the order of the code.
$image = imagecreatefromjpeg("image.jpg");
unlink("image.jpg");
imagejpeg($image,"image.jpg",50);
This allows you to compress a pre-existing image and store it in the same location with the same filename.

How to get the thumbnail of a video file using php and save it as a jpg? [duplicate]

Is there a way in PHP given a video file (.mov, .mp4) to generate a thumbnail image preview?
Solution #1 (Older) (not recommended)
Firstly install ffmpeg-php project (http://ffmpeg-php.sourceforge.net/)
And then you can use of this simple code:
<?php
$frame = 10;
$movie = 'test.mp4';
$thumbnail = 'thumbnail.png';
$mov = new ffmpeg_movie($movie);
$frame = $mov->getFrame($frame);
if ($frame) {
$gd_image = $frame->toGDImage();
if ($gd_image) {
imagepng($gd_image, $thumbnail);
imagedestroy($gd_image);
echo '<img src="'.$thumbnail.'">';
}
}
?>
Description: This project use binary extension .so file, It's very old and last update was for 2008. So, maybe don't works with newer version of FFMpeg or PHP.
Solution #2 (Update 2018) (recommended)
Firstly install PHP-FFMpeg project (https://github.com/PHP-FFMpeg/PHP-FFMpeg)
(just run for install: composer require php-ffmpeg/php-ffmpeg)
And then you can use of this simple code:
<?php
require 'vendor/autoload.php';
$sec = 10;
$movie = 'test.mp4';
$thumbnail = 'thumbnail.png';
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open($movie);
$frame = $video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds($sec));
$frame->save($thumbnail);
echo '<img src="'.$thumbnail.'">';
Description: It's newer and more modern project and works with latest version of FFMpeg and PHP. Note that it's required to proc_open() PHP function.
Two ways come to mind:
Using a command-line tool like the popular ffmpeg, however you will almost always need an own server (or a very nice server administrator / hosting company) to get that
Using the "screenshoot" plugin for the LongTail Video player that allows the creation of manual screenshots that are then sent to a server-side script.
I recommend php-ffmpeg library.
Extracting image
You can extract a frame at any timecode using the
FFMpeg\Media\Video::frame method.
This code returns a FFMpeg\Media\Frame instance corresponding to the
second 42. You can pass any FFMpeg\Coordinate\TimeCode as argument,
see dedicated documentation below for more information.
$frame = $video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(42));
$frame->save('image.jpg');
If you want to extract multiple images from the video, you can use the following filter:
$video
->filters()
->extractMultipleFrames(FFMpeg\Filters\Video\ExtractMultipleFramesFilter::FRAMERATE_EVERY_10SEC, '/path/to/destination/folder/')
->synchronize();
$video
->save(new FFMpeg\Format\Video\X264(), '/path/to/new/file');
By default, this will save the frames as jpg images.
You are able to override this using setFrameFileType to save the frames in another format:
$frameFileType = 'jpg'; // either 'jpg', 'jpeg' or 'png'
$filter = new ExtractMultipleFramesFilter($frameRate, $destinationFolder);
$filter->setFrameFileType($frameFileType);
$video->addFilter($filter);

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?

Imagemagick - PDF to Jpeg/Raster texture issue

I am using imagemagick/php to make a jpeg file from a PDF.
Input PDF file:
PDF-file
Output Jpeg file:
Jpeg-file
The textures on the output file look wrong near the bottom. This is the same result if I make a PNG also. I have tired different floor plans, other textures play up also in a similar way.
PHP code
$im = new Imagick();
$im->setResolution( 300, 300 );
$im->readImage( $input_path );
$im->setImageFileName($output_path);
$im->writeImage();
Server Config
PHP Version 5.3.5
ImageMagick 6.4.8
Thank you.
It looks like ImageMaigck handles opacity in embedded images in PDFs incorrectly. I am not familiar enough with ImageMagick to have a solution for you, but it is discussed here in their documentation -- perhaps there is an option you can change to improve things.

Some problems related to generate antispam(captcha) in jpgraph

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

Categories