I know there are packages in Laravel like this for converting PNG/JPG images to WebP but this package is in php7.1 so we cannot use it for technical reasons, there is also an imagewebp() function in php which we would like to use it, but I cannot find any documentation for how to read an already existing image and give it to the function to convert it to the WebP image. Does any one have a solution on how to read an image file and give it convert it to the WebP images using the PHP extensions?
Related
I am working on a website for my client in which tiff images need to converted to png or jpg before they are assembled into a PDF.
I have read many articles, here and other sites, on this issue. They all recommend using Imagick to accomplish this. The problem is, my client's server does not have that extension installed, and the hosting company is unwilling to install the extension.
Nor is PDFLib installed on the server (which supports importing tiffs into a PDF).
Thanks.
This is tricky because of the tiff format. You can do this for most input formats with native PHP functions to create an image object from the source file and then save that using imagejpeg or imagepng. But tiff has patent issues and I don't think it's supported. Have a look at the PHP GD and image functions available on your server. May be some help in the comments here: http://php.net/manual/en/function.pdf-open-image-file.php
I want to convert pdf files to jpg without use of imagemagick and ghostscript, if anyone have an idea please help me.
Try using an online conversion service instead.
For example transloadit provides an API which can be used to extract images from PDF files (https://transloadit.com/docs/extracting-images-of-documents). They even provide ready development kits for PHP (https://transloadit.com/docs/development-kits#php-sdk).
Cloudinary could be an alternative as well.
If you instead what to work around the error with ghostscript open another question with detailes for that provided.
How do I get a coordinate (x,y) of an image from the PDF file using PHP?
For example, I have a PDF document page, I know the size of the page, there I have one image, I know its size too (because I've extracted it using the pdfimages tool). However, I need to know where was this image situated on the page.
I've read that it maybe could be done using FPDF but I couldn't understand how.
To get PDF images with their coordinates, ImageData and size informations, you have to get PDFlib You can get the PECL free version here and TET (Text Extraction Toolkit) here.
After configuring PDFlib and TET and linking both of them to your php's extension on the php.ini (extension=pdf.so and extension=php_tet.so), you will have a bunch of examples in the directory where you installed PDFlib (where you typed ./configure && make && make install or where you get the "php_tet.so"). Open them to see how to use the functions. This lib is object oriented.
With it you can get all the images (coordinates, size and create a jpeg file) and texts (size, font and coordinates) of each pages of a PDF.
I'm at your service if you have other questions or if a point is not clear to you ;)
P.S Sorry my english is not very good
An option would be to convert your pdf to an image (there are scripts available to do so, didn't try it but this might do the job)
Then you can use the code I posted on your other question to locate an image inside another image.
With PHP i'm creating an image with embedded content (base64 encoded files). If i see it using Firefox, or downloading it and then opening it with Inkscape (www.inkscape.org), the image is fine!.
But when i try to convert it using imagemagick (using convert command or with Imagick support for PHP) the embedded image doesn't come in with the final result.
I don't know if there is a special command or configuration i'm missing. I'm not using any special setup. Just ...
convert image.svg image.png
Thank you very much for your answer.
ImageMagick's built-in SVG rendering is really pretty horrible. Don't use it if you can avoid it. I'd recommend using librsvg instead, either using the command-line rsvg tool, or possibly with the PHP rsvg extension.
(Librsvg's rendering isn't always perfect either, but it should be able to handle embedded images just fine. If you want even better rendering, you could always try using Inkscape from the command line.)
Is the embedded image in PNG or in Jpeg format? What converter is used in PHP? I tried on Windows with latest ImageMagick, which doesn't come with RSVG. I found a RSVG-Converter build for Windows, and, while it does a good job, it skips the Jpeg version of the image of a test file.
On the other hand, the built-in converter handles correctly both images, but does an awful job on the home image shown in the SVG tutorial.
These are the steps I am trying to achieve:
1) Upload a PDF document on the server.
2) Convert the PDF document to a set of images, and saving them.
Any ideas for doing #2 using php??
If you have the ImageMagick extension compiled into PHP, it should be able to read in PDFs and convert them to any common image format. I don't believe the GD extension (which is more common) has PDF capabilities, sadly.