how to convert any image file into EPS format in PHP? - php

I have an image processing system in PHP with Imagemagick. The existing system will be processing images of EPS format for some process and PNGs for the remaining process. So, I need to upload the same image file in EPS and PNG. I am doing the file upload facility now, which should automate the procedure of converting any format image file into EPS and PNG and should save in corresponding locations.
What I need now is to be able to convert any image format file into EPS and PNG, so then I can process and save them, but there are some DPI limitations. So I need to save the files into these EPS and PNG formats so that only the existing system can use those files properly.
Please advice me if there is any way to convert image files into EPS and PNG with PHP and Imagemagick.
Thanks in advance.

You can convert any image to eps format by following code
public function convertImageToEps(){
$imgUrl = WWW_ROOT.'imfcs.jpg';
$imagic = new Imagick();
$imagic->readImage($imgUrl);
$imagic->setImageFormat('eps');
$imagic->writeImage(WWW_ROOT.'simfcs.eps');
return true ;
}

Related

PDF to Image Conversion - PHP

Note: PDF files would be uploaded by user.
I am making a document sharing website(pdf). I don't want users to be able to copy/select the pdf file text. I am looking for a nice PDF/Image Document viewer. Currently using the following method:
I am using imagemagick to convert PDF file to Jpeg. But the process is too slow even after disabling OpenMP. I was looking forward to convert full PDF to different image files but decided to just convert the first image to a thumbnail because the process is so slow.
I am using it on my local machine and it takes more than 30 seconds to convert 40-50 pages in good quality. So if there are pdf files more than 100 pages, this process would ruin the user experience.
Is there any way to convert PDF to Image files?
Also is there a way to let this process (pdf to image) happen asynchronously? Like the user filling out file details while the pdf is being uploaded and converted, something like YT videos?
Enter the command in exec() function, this will help you out
<?php
$pdf_url = 'testfile.pdf'; // Url of the PDF
$image_name = 'output.jpg'; // Set the image name
exec('convert "'.$pdf_url.'" -colorspace RGB -resize 800 "'.$image_name.'"', $output, $return_var);
?>
Hope this helps you
¿You use a linux sever?
Just use convert command and put [0] sufix to pdf file for save a cover:
exec("convert '/home/sample.pdf[0]' '/home/test.png'");

Resize and Convert all uploading image into png format

First I want to tell you guys I'm a beginner to this. I'm developing a website, I want to allow users to upload any size of images in a variety of formats (GIF,JPEG,PNG).
And I want to re size the image and convert the image format into PNG. Im not inserting the image into database as BLOBs.
this is my code, But I'm uploading the image directly here, How to re size and convert to PNG:
$myImage = $_FILES['imgCover']['name'];
$response = mysql_query("INSERT INTO gallery (imagename) VALUE ('$myImage')");
if($response === true)
{
move_uploaded_file($_FILES['imgCover']['tmp_name'],"images/gallery/".$_FILES['imgCover']['name'])
}
Please help me.
Something like http://salman-w.blogspot.com/2008/10/resize-images-using-phpgd-library.html?
Just use png where its says jpeg, like
imagejpeg
etc.

How to convert .png file to .bmp?

I need to convert a .png file to .bmp; I'm using the outcome in printer_draw_bmp() to print out a barcode.
GD can generate WBMP, but as far as I can tell that's not the same as .bmp. How can I do this conversion? Or is there another way to print a .png directly?
There is a opensource project on Github that allows reading and saving of BMP files (and other file formats) in PHP.
The project is called PHP Image Magician.
AFAIK, GD doesn't support bmp format. But you can use ImageMagick to save file in bmp format:
$im = new Imagick('image.png');
$im->writeImage('image.bmp');
Or if you want to output image to http response:
$im = new Imagick('image.png');
$im->setImageFormat('bmp');
echo $im;

PHP Image Convert

In my web app users are allowed to upload images as their photos. How can I convert different image extensions to JPG? Input files are JPG, PNG or GIF.
Personally, I prefer Image Magick over GD. It's a lot better if you're dealing with large images too; you can run into memory allocation issues with GD.
With php, you can convert any image to an other using imagepng, imagejpeg, imagegif :
imagepng(imagecreatefromstring(file_get_contents($input)), 'output.png');
In this example, it will save the uploaded image in png with the path 'output.png'
You can use PHP GD.
For anybody who would want to get the binary out of a temporary file, here is my solution:
<?php
$temp = tmpfile();
imagepng(imagecreatefromstring($imgBinary), $temp);
$pathFile = stream_get_meta_data($temp)['uri']; // eg: /tmp/phpFx0513a
$pngBin = file_get_contents($pathFile)
?>

Generate Thumbnails with PHP for a wide range of file formats

I have had a client request on a upload facility for his clients, but after upload that a image thumbnail to be created.
All normal images are ok but he his talking about .psd, .pdf, .eps, .ppt
Having a good look around I think wih imagemagick & ghostscript will cater for most of these but I cant find a solution of PPT or EPS.
Im hoping that imagemagick will be able to do eps as it can do a psd.
Any suggestion on EPS or PPT file format.
Thank you if you can advice.
I'm late to the party I know, however...
This is what I use for .PDF, .EPS and .AI thumbnailing. (Assuming all necessary ImageMagick distros installed)
$file = 'filename.pdf.eps.ai';
$cache = $_SERVER['DOCUMENT_ROOT'].'/cache/';//ensure dir is writeable
$ext = "jpg";//just the extension
$dest = $cache.$file.'.'.$ext;
if (file_exists($dest)){
$img = new imagick();
$img->readImage($dest);
header( "Content-Type: image/jpg" );
echo $img;
exit;
} else {
$img = new imagick($_SERVER['DOCUMENT_ROOT'].'/'.$file.'[0]');
$img->setImageFormat($ext);
$width = $img->getImageheight();
//$img->cropImage($width, $width, 0, 0);
$img->scaleImage(105, 149, true);
$img->writeImage($dest);
header( "Content-Type: image/jpg" );
echo $img;
exit;
}
Don't know why it works, but it does - One code to rule them all right?
PPT is a powerpoint presentation. So creating an image that is a PPT would require some library that can pull this off.
Here are some resources to help you out.
Generate Powerpoint file on the fly
EPS is a vector format, so not unless you have your image as vector objects, you wont be able to do this correctly.
Just some thoughts - none of these things has been tested by myself.
EPS:
You should be able to convert your EPS to a PDF with ghostscript. Using imagemagick & ghostscript you can convert the PDF to some bitmap format (GIF, PNG or JPG).
PPT:
This seems to be somehow more complicated. If your are on a Windows machine you could resort to use the Powerpoint API from within a small hand-written converter. Another possibility would perhaps be to use Apache POI-HSLF whichs is a Java API to the Powerpoint file format. This would require a Java program for the conversion process. The last resort could be that study the Powerpoint binary file format and see if there is e.g. a thumbnail embedded (perhaps beeing used for the file icon in Windows Explorer) that could be extracted.
You could find some free icon sets and use a default icon for all .ppt file and another for all .eps. You can then further extend this for all file formats that cannot be converted to a image, such as audio files. Not the perfect solution but something a user may feel more comfortable with then just having text.

Categories