PHP image trace function [duplicate] - php

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Sourcecode to convert JPG (bitmap) to SVG (vector)?
Is there an existing php library that can do an image trace function? If not, how would this be accomplish-able? Is there an existing library that could be easily ported to php?

You can use OpenCV's feature detection functionality to detect and trace edges. OpenCV is very good at these type of image processing and is widely used and developed.
There is also a PHP library to interface with OpenCV.

Just found this, which is a tutorial on tracing a bitmap in Inkscape. You might have to dig about in the internals of the program to be able to interface it in PHP, but perhaps that might get you started?
Edit: this uses Potrace internally, which I suspect works at the command line. Image in, SVG/PDF out - easily interfaced in PHP.

Related

How can I convert videos in php without using ffmpeg? [duplicate]

This question already has answers here:
How to install ffmpeg for PHP
(2 answers)
Closed 6 years ago.
I made a code in php that extracts mp3 audio track from a video file using the exec function to execute ffmpeg.
All works fine on a local server using WAMP on windows. But when deploying the script to the server, I can not run ffmpeg anymore because the server does not have the software.
Is there a class in pure PHP, or an API that is capable of the same or at least the basic ffmpeg functionality?
But when deploying the script to the server, I can not run ffmpeg anymore because the server does not have the software.
It's easy to get ffmpeg on your server:
Download a static build of ffmpeg for Linux, Windows, or OS X.
Point your script to it.
Encode.
See FFmpeg Wiki: PHP.
EDITED:
As any conversion is very CPU intensive, there is no pure PHP solution and in near future never will be.
For conversion you can use https://cloudconvert.com/ that provides rest api and asyncronous conversions.
First your question title mentions "videos", but the question body asks about MP3s, could you please clarify?
Second, just because the server does not have ffmpeg this does not mean you cannot install it. This probably should be the option to pursue - and if the host is that strict, it is unlikely you'd be able to install any other solution anyway.
PHP as a language does not have MP3 decoders, and while it is possible to write one, or even to find one already written, I would avoid it. Parsing multimedia formats is tricky, as recent Stagefright bug in Android proved, so you'd be better using a well-tested and supported frameworks such as GStreamer or FFMpeg.
Also if you need to convert only certain formats such as MP3, you can look at MP3 decoders such as lame.

how sign a xml and pdf use a digital signature in php [duplicate]

This question already has answers here:
How to add digital signature (RSA, Certificate, etc) to any of file, using PHP?
(3 answers)
Closed 8 years ago.
Someone could give me tips on how to do this in php, i have a .cert file and rsa key and need sign to xml from invoice. Also need sign a pdf file, any ideas?
Thx
There seems to be no PHP-only way to sign XML and PDFs according to XMLDSig and PDF standards, though you can sign using PKCS#7 with OpenSSL functions.
If you need XMLDSig and PDF signing, your best option is to create an executable for your platform and call it from PHP somehow.
Within our SecureBlackbox product we are working on PHP edition, but it will be a wrapper for a native .dll/.so library, not PHP-only solution. The reason is that it makes no sense to translate the enormous amount of cryptography-related code to PHP.
What about running the signing process in shell?
shell_exec("gpg --output signature.sig --sign file")
And then provide the signature.sig for download.
I don't see what the filetype has to do with it. gpg signs files regardless of content/type/...

Why can't I compile PHP code? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Can you “compile” PHP code?
After I write an application in PHP, why can't I compile it into machine language? I know that it's possible to make a byte-code version of the file, which (as I understand it) is basically a file that has already been parsed into tokens.
But that's not what I want. Clearly it can't work in a general sense, since compiled code will be platform-specific, but let's say I have chosen a given platform. Why can't I create a binary file that would be the same code that PHP would run when given my .php file?
You can, facebook released a project which is currently being updated for php 5.3 (supports everything lower iirc) called HipHop, you can find it here: https://github.com/facebook/hiphop-php
There are a few compilers out there like facebook's, mentioned by #Howard, or http://www.roadsend.com/home/index.php?pageID=compiler. I've never tried them though.

Open documents(pdf,doc,docx,txt) in browser page using php (without using google docs viewer) [duplicate]

This question already has answers here:
Is there a PDF parser for PHP? [closed]
(7 answers)
Closed 8 years ago.
My question is that i want to open documents(pdf,doc,docx,txt) in browser page using php (without using google docs viewer) can any one help me?
Some of these are doable. Some, not so much. Let's tackle the low-hanging fruit first.
Text files
You can just wrap the content in <pre> tags after running it through htmlspecialchars.
PDF
There is no native way for PHP to turn a PDF document into HTML and images. Your best bet is probably ImageMagick, a common image manipulation program. You can basically call convert file.pdf file.png and it will convert the PDF file into a PNG image that you can then serve to the user. ImageMagick is installed on many Linux servers. If it's not available on your host's machine, please ask them to install it, most quality hosts shouldn't have a problem with this.
DOC & DOCX
We're getting a bit more tricky. Again, there's no way to do this in pure PHP. The Docvert extension looks like a possible choice, though it requires OpenOffice be installed as well. I was actually going to recommend plain vanilla OpenOffice/LibreOffice as well, because it can do the job directly from the command line. It's very unlikely that a shared host will want to install this. You'll probably need your own dedicated or virtual private server.
In the end, while these options can be made to work, the output quality is not guaranteeable. Overall, this is kind of a bad idea that you should not seriously consider implementing.
I am sure libraries and such exist that can do this. Google could probably help you there more than I can.
For txt files I would suggest breaking lines after a certain number of characters and putting them inside pre tags.
I know people will not be happy about this response, but if you are on a Linux environment and have pdf2html installed you could use shell_exec and call pdf2html.
Note: If you use shell_exec be wary of what you pass to it since it will be executed on the server outside of PHP.
I thought I'd just add that pdfs generally view well in a simple embed tag.
Or use an object so you can have fall backs if it cannot be displayed on the client.

How can I modify exif data of an image with PHP [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
How do I add exif data to an image?
I want to modify some information in exif data with PHP. I've googled around but no hope. There's function in PHP, exif_read_data. But it only reads not writes. Anybody knows how or walkaround?
Looks fairly old but may be something for you: http://pel.sourceforge.net/
This gets also mentioned in the linked article from Calvin L.
http://pel.sourceforge.net/
A php extension that can write exif data, with installation instructions using PEAR. It requires that you can control which extensions are being installed on the machine that runs your PHP, which is not the case in many virtual hosting environments.

Categories