Using imagick montageImage PHP - php

I'd like to use imagemagick to make a montage from existing photos on my server. I am having a terrible time getting any code to work properly. I've tried using the few examples I've found by searching, but it's not working.
http://us1.php.net/imagick outlines the library beautifully, but there are no montage examples. I'd just need a proper example to get me off on the right foot and I' can usually take it from there.
Does anyone know of a good resource to learn imagick for PHP?

Here is a working example of montageImage. The example does a color analysis of a photo. To make sure it works properly, you will need to make sure:
You have a valid "test.png".
Imagick::clone has been deprecated as of imagick 3.1.0 in favour of using the clone keyword. So if you have imagick 3.1.0, you will need to change lines 13 and 17.
$bright = $average->clone();
to
$bright = clone $average;
and
$dark = $average->clone();
to
$dark = clone $average;
Good luck.

Did you start with the basic example?
http://us1.php.net/manual/en/imagick.examples-1.php

Related

strtotime compatibility

Ok this relates to another question I have asked but as I have now pinpointed
the issue I thought it would be clearer on a new question.
The problem I am having relates to strtotime under PHP 4.4
I have a larger script that is failing under PHP 4.4 but works under PHP 5+
To check it was this I wrote the following and copied it to two servers one
running PHP 4.4 and the other PHP 5.3.
<?php
$my_time = '2013-03-18T21:38:58.000Z';
$my_time = strtotime($my_time);
echo $my_time;
?>
The output under PHP 4.4 was: -1
The output under PHP 5.3 was: 1363642738
Is there a way to get the same result under PHP 4.4 as 5.3??
Thanks in advance for any help!
-1 was the failure code for PHP < 5.1. This makes me think that PHP 4 can't parse that string.
This means you'll have to use a format both versions support. As a hack, you could do some string manipulation. If you can change the format of the string though, that's your best route. (Actually, your best route is to run the hell away from PHP 4.)
I don't have an installation of PHP 4 to test with, but try removing the .000Z from the end, all the examples on the strtotime page on PHP.net don't have that bit PHP 4.4 may not support it.
If that works ultimately you can parse any time stamps with a substr($my_time, 0, 19)

PHP library to generate code diff (github style)?

I'm looking for an free php library that can generate code diff HTML. Basically just like GitHub's code diffs pages.
I've been searching all around and can't find anything. Does anyone know of anything out there that does what I'm looking for?
It looks like I found what I'm looking for after doing more Google searches with different wording.
php-diff seems to do exactly what I want. Just a php function that accepts two strings and generates all the HTML do display the diff in a web page.
To add my two cents here...
Unfortunately, there are no really good diff libraries for displaying/generating diffs in PHP. That said, I recently did find a circuitous way to do this using PHP. The solution involved:
A pure JavaScript approach for rendering the Diff
Shelling out to git with PHP to generate the Diff to render
First, there is an excellent JavaScript library for rendering GitHub-style diffs called diff2html. This renders diffs very cleanly and with modern styling. However diff2html requires a true git diff to render as it is intended to literally render git diffs--just like GitHub.
If we let diff2html handle the rendering of the diff, then all we have left to do is create the git diff to have it render.
To do that in PHP, you can shell out to the local git binary running on the server. You can use git to calculate a diff on two arbitrary files using the --no-index option. You can also specify how many lines before/after the found diffs to return with the -U option.
On the server it would look something like this:
// File names to save data to diff in
$leftFile = '/tmp/fileA.txt';
$rightFile = '/tmp/fileB.txt';
file_put_contents($leftFile, $leftData);
file_put_contents($rightFile, $rightData);
// Generate git diff and save shell output
$diff = shell_exec("git diff -U1000 --no-index $leftFile $rightFile");
// Strip off first line of output
$diff = substr($diff, strpos($diff, "\n"));
// Delete the files we just created
unlink($leftFile);
unlink($rightFile);
Then you need to get $diff back to the front-end. You should review the docs for diff2html but the end result will look something like this in JavaScript (assuming you pass $diff as diffString):
function renderDiff(el, diffString) {
var diff2htmlUi = new Diff2HtmlUI({diff: diffString});
diff2htmlUi.draw(el);
}
I think what you're looking for is xdiff.
xdiff extension enables you to create and apply patch files containing differences between different revisions of files.
This extension supports two modes of operation - on strings and on files, as well as two different patch formats - unified and binary. Unified patches are excellent for text files as they are human-readable and easy to review. For binary files like archives or images, binary patches will be adequate choice as they are binary safe and handle non-printable characters well.

Auto New Line In GD Library

I'm using the GD Library to create images from data I'm pulling from an API.
The strings that are returned can sometimes be kind of lengthy, and I'm hoping to find a way to automatically create a new line for text if the string goes too far.
Is there something like this built into the GD library, or will I have to write some code to count the characters and move everything to a new line if it goes too long?
GD is strictly for drawing. You'll need a text layout engine such as Pango.
I am not familier with a built-in function that automatically creates new lines,
so I guess you need to write a php function that sorts the string to "sub-strings"
according to your width length and then use them in your image.
Consider looking at this post:
http://www.php.net/manual/en/function.imagestring.php#90481

Video thumbnail generation imagemagick?

I have been searching for an alternative to ffmpeg (I'm on a host that doesn't allow ffmpeg or mencode due to server power or something) and I was looking into GD or Imagemagick (both of which are installed) is there a way to generate a video thumbnail from either of these two libraries or another one?
I also have the option of using ruby on rails or python or CGI/perl to do the generation. But I'm not skilled in either of those languages so I would need a tutorial or script already wrote.
Anyone help?
Imagemagicks Convert can do video tumbnails.
convert -quiet moviefile.mov[10] movieframe.gif
where the number between the [] is the framenumber of the movie that is converted
In fact, ImageMagick just uses ffmeg under the hood. If ffmpeg is not installed, you'll have no luck using ImageMagick
As tijej said you must need ffmpeg in order to use ImageMagick. If you are OK with that you can also use FFmpeg::Thumbnail module.
Sample:
my $baz = FFmpeg::Thumbnail->new( { video => '/my/video/file.flv' } );
$baz->output_width( 640 );
$baz->output_height( 480 );
$baz->offset( 21 );
$baz->create_thumbnail( undef, '/my/first/thumbnail.png');

convert txt or doc to pdf using php

have anyone come across a php code that convert text or doc into pdf ?
it has to follow the same format as the original txt or doc file meaning the line feed as well as new paragraph...
Converting from DOC to PDF is possible using phpLiveDocx:
$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
$phpLiveDocx->setUsername('username')
->setPassword('password');
$phpLiveDocx->setLocalTemplate('document.doc');
// necessary as of LiveDocx 1.2
$phpLiveDocx->assign('dummyFieldName', 'dummyFieldValue');
$phpLiveDocx->createDocument();
$document = $phpLiveDocx->retrieveDocument('pdf');
file_put_contents('document.pdf', $document);
unset($phpLiveDocx);
For text to PDF, you can use the pdf extension is PHP.
You can view the examples here.
Have a look at this SO question. Using OpenOffice in command line mode for conversions can be done, though you'd have to search a bit for the conversion macro's. I'm not saying it's light-weight though :)
See HTML_ToPDF. It also works for text.
It has been a long time since I touched PHP, but if you can make web service calls from it then try this product. It provides excellent conversion fidelity. It also supports additional formats including Infopath, Excel, PowerPoint etc as well as Watermarking support.
Please note that I have worked on this product so the usual disclaimers apply.

Categories