I have audio files on my server and wanted to convert them into flac format in order to convert them into text. Please let me know how can we achieve that..
You can use FFmpeg:
https://ffmpeg.org/
ffmpeg -i input.mp3 output.flac
There is a php wrapper for the ffmpeg binary on github.
https://github.com/PHP-FFMpeg/PHP-FFMpeg
In case you can't install ffmpeg you might want to try this free API:
<?php
$url = 'http://server.com/sound.mp3';
$data = json_decode(file_get_contents('http://api.rest7.com/v1/sound_convert.php?url=' . $url . '&format=flac'));
if (#$data->success !== 1)
{
die('Failed');
}
$flac = file_get_contents($data->file);
file_put_contents('sound.flac', $flac);
Related
I need help in to read text from image whatever we upload.Is there any library for this. I am using Tesseract PHP OCR.
But not getting idea to use it . I am attaching my file here.
Tesseract file is from here: https://github.com/thiagoalessio/tesseract-ocr-for-php/tree/master/src
and my php i have written attached image.enter image description here
Here is a little script I use to do ocr for pdfs on ubuntu 16.04
$inputPDF = 'path/to /your/file';
$fileToOCR = "ocr.tiff";
exec("convert -density 300 $inputPDF -depth 8 -strip -background white -alpha off $fileToOCR");
$outputOCR = "ocr";
exec("tesseract $fileToOCR -l deu+eng $outputOCR hocr");
note that you need tesseract-ocr and imagemagick installed sudo apt-get install tesseract-ocr imagemagick
also you need the language packs you want to use sudo apt-get install tesseract-ocr-[lang]
exec("convert ..."); prepares the file for better results
exec("tesseract ... "); does the actual ocr where deu+eng is the language from the text and hocr is the output format (xml with additional infos where the text was found)
hope it helps
Hello you can use this libary for that
https://www.phpclasses.org/package/3312-PHP-Hide-encrypted-data-in-images-using-steganography.html
You can use this API (it's free):
<?php
$url = 'http://server.com/image.png';
$data = json_decode(file_get_contents('http://api.rest7.com/v1/ocr.php?url=' . $url . '&format=txt'));
if (#$data->success !== 1)
{
die('Failed');
}
$txt = file_get_contents($data->file);
file_put_contents('text.txt', $txt);
You should just replace $url with URL to your image file and the output will be save as text.txt.
Has anybody had any experience with generating 2D Barcodes for Royal Mail via PHP? I've spent a while attempting to get my own routines to write a valid datamatrix sadly to no avail.
I do have working conversion routines for ASCII to C40 and Luhn 16 checksum makers but just can't get anywhere with the graphical representation, or the ECC200 byte creation for that matter.
Are there any pre-written libraries out there with documentation that would help take away a lot of further legwork?
I do need to be able to generate this within the server environment, without using external sites ofr image generation ideally.
We use Zint Barcode Generator Unix packages for QR and PDF417 code generation. Royal Mail is supported as well.
(on CentOS dnf install zint, Ubuntu takes more work).
Zint documentation: http://www.zint.org.uk/
In PHP use the system method, example:
$targetFilePath = dirname(__FILE__).'/test.png';
$contents = 'ABC123';
system('zint ...params... -o"' . $targetFilePath . '" -d"' . $contents . '"');
var_dump(file_exists($targetFilePath));
It will generate an image on the requested $targetFilePath.
For ECC200 Datamatrix Generation in PHP we successfully used:
sudo apt install dmtx-utils
To output a PNG file from the server, with normal apache2 settings you would get
the barcode in PNG when you enter in the browser: http://yourserver.com/datamatrix/?in=yourbarcodetext
<?php
ob_start();
$old_path = getcwd();
$infile = "/var/www/html/datamatrix/message2.txt";
$image = "/var/www/html/datamatrix/image.png";
file_put_contents($infile,$_GET["in"]);
$ex = "export HOME=/tmp && /usr/bin/dmtxwrite {$infile} -o {$image}";
echo "<b>$ex</b>";
$output = shell_exec($ex);
echo var_export($output, TRUE);
echo "done";
chdir($old_path);
$im = imagecreatefrompng($image);
ob_end_clean();
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
i have installed imageMagick and ghostscript from online and put it inside mamp but m not getting how to include them in my php code..
by googling i found a code
<?php
$pdf = 'serviceReport.pdf';
$save = 'output.jpg';
exec('convert "'.$pdf.'" -colorspace RGB -resize 800 "'.$save.'"', $output, $return_var);
?>
but m not getting the result..can anyone help with this
It is much effective to use the php extension ImageMagick offers (Imagick) instead of command line tools:
<?php
// ...
$img = new \Imagick();
$img->readimage($filedata['tmp_name']); // this can be a pdf file!
$img->setResolution(300,300);
$img->writeImage(sprintf('%1$s/%2$s.jpg', $basepath, $basename));
// ...
?>
Another alternative is to use the poppler tools instead. They offer much faster processing.
I have a live stream from a Tenvis IP camera through http live streaming and its in mjpeg compression.
I am trying to save it to a file, and I have tried using php to do this. my code looks like this:
<?php
$input = fopen("http://xxx.xxx.xxx.xxx:81/videostream.cgi?user=user&pwd=admin&resolution=8");
$output = fopen("video.mpg", "c+");
$end = time() + 60;
do {
fwrite($output, (fread($input, 30000)), 30000);
} while (time() <= $end);
fclose($output);
fclose($input);
echo "<h1>Recording</h1>";
?>
The code I have creates the file but doesn't write anything to it. Any suggestions will be appreciated
According to the Wikipedia page about MJPEG (http://en.wikipedia.org/wiki/Motion_JPEG#M-JPEG_over_HTTP), the MJPEG stream over HTTP is basically a sequence of JPEG frames, accompanied by a special mime-type. In order to capture these and save them to a video file, I am not sure you can simply write the incoming data to an .mpg file and have a working video.
To be honest, I am not quite sure why your script does not write anything at all, but I came across the following page, which, although it is written for specific software, provides examples on how to capture an MJPEG stream and pass it on to a browser:
http://www.lavrsen.dk/foswiki/bin/view/Motion/MjpegFrameGrabPHP
You could try one of their examples, and instead of passing it to the browser, save it to a file. You can see they read one image at a time:
while (substr_count($r,"Content-Length") != 2) $r.=fread($input,512);
$start = strpos($r,'ΓΏ');
$end = strpos($r,$boundary,$start)-1;
$frame = substr("$r",$start,$end - $start);
If this does fix the stream capturing part but not saving it as a video, another option would be to save all frames individually as a JPEG file, then later stitch them together using a tool such as ffmpeg to create a video: Image sequence to video quality
Update
If you decide to take the ffmpeg road, it is also possible to capture the stream using ffmpeg only. See this question for an example.
Hope this helps.
Most of the time, when a camera supports mjpeg, it also supports rtsp and as such you might want to pursue that as a solution for what you are trying to accomplish. With that, its fairly simple to record using an app like VLC.
on server side I have an generated SVG XML source code.
This should be changed to an image in order to offer a PNG (or JPG) download from an SVG XML code.
Searching the web for a long time, I only found this solution using ImageMagick.
Convert SVG image to PNG with PHP
But I don't have access to the ImageMagick library so I need a different way to convert SVG XML Code to a bitmap image.
Does anybody have an idea?
Brw: It's not an option to save that svg an execute an binary or script on operating system to convert.
Thank you.
You need to use batik library. Download it, placed somewhere in your project. Then in php call the batik command using shell_exec() function. It will take few seconds and convert you svg to png.
Example:-
outputfile ='path where you want to lace png'
$tempSVG_filename = '/var/www' . $baseUrl . '/png/temp.svg';
$tempSVG_handle = fopen($tempSVG_filename, 'w+');
fwrite($tempSVG_handle, $YourSVG);
fclose($tempSVG_handle);
$mimetype = 'image/png';
$width = '6000';
$result = shell_exec('java -jar /var/www/svgtopng/batik-1.7/batik-rasterizer.jar -m ' . $mimetype . ' -d ' . $outputfile . ' -w ' . $width . ' ' . $tempSVG_filename . ' 2>&1');
unlink($tempSVG_filename);