How to connect ghostscript with imagecreatefrompng in PHP? - php

I am currently using ghostscript, via exec() from PHP, to create a PNG image that is saved to a file.
And then I use imagecreatefrompng() to load it into PHP. I am wondering if there is a way to directly connect these without first saving it to a file and then reading it from a file. Does this work with the expect:// wrappers? If so could somebody provide an example? I am not sure about the syntax.
Another solution may perhaps be with imagecreatefromstring() if one can get the image file as a string from ghostscript. I am looking for an example of how to do this. The image files I create are not that large, typically 600 x 150 pixels.

Related

TIFF image Rotation Using PHP

My Problem is:
I want to upload the tiff image and then i want to rotate that image automatically such that it is oriented correctly . And then user can download that correctly oriented tiff image.
I want to use PHP.
Thanks.
Without lib i don't think it's possible because tiff is an adobe format.
I think you should use command line of gimp with parameters or with another program like photoshop and save your image after oriented.
With php and exec function i think perhaps it's possible.

Is there any way to convert pdf file to jpg without imagemagick or ghostscript.?

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.

Coordinates of images in PDF using PHP

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.

batch image processing cronjob in php

i need to import images from a third party source. the import file looks like:
// import.csv
group1;nameofimage1;http://www.site.com/image/image1.jpg;nameofimage2;http://www.site.com/image/image2.jpg; etc...
you can have up to 20 images per line.
i have a cronjob that reads the file and then process it (loop each line, parse each line then curl to get the image etc.. - that im ok).
the image provided are way too big for what i need and for each file i need to resize them to 50% of their original size. i tried to use the gd library but it takes a very long time to complete.
is it normal? what can i use to make it faster?
thansk
GD library is not optimized for big images.. actually I'd NOT recommend to use GD at all.. only if you don't have other options..
ImageMagick is your wizard here :)
And other small bit. Better is to not use PHP for this task. You can use command line imagemagick tools for this. Just add another line to your cron/bash script to automatically resize images if needed.

Upload merged Images and then break apart with PHP

Looking for a way to enable someone to upload a single file which will be series of image files (all gif) merged together as one big file. Here is what I need to do:
Using VB6, want to merge the image files (potentially dozens of them) into a single file
Upload file to a PHP Script (easy enough)
Have PHP break apart the single file and write image files
I know how to handle the uploading of the file. I also know how to write the image files in PHP. What I am unsure of is the merging/un-merging operation.
In theory, I should just be able to use VB6 to merge all images using binary read/writing. However, does anyone know the series of binary codes that prefix each .gif file so PHP can pick up on that, or do I need to write some sort of binary separator in between each merged image?
I could surely tinker with this myself, but I thought some of you smarter-than-me coders may have already done this, and/or could provide a link, some code, or some 'things to consider'.
Thanks.
Instead of merging/un-merging, if the whole purpose is to avoid overhead of sending dozens of files, why not zipping them and unzipping in PHP?
That should be far easier than the merging operation you're proposing.
Here's a free Zip/Unzip library for Windows: Info-ZIP
Here's some sample code that uses Info-ZIP: Zip and Unzip Using VB5 or VB6
Here's PHP's documentation on the ZIP module: php.net/zip
Here's an example of how to use "unzip" command through PHP, rather than using the Zip module: Zipping and Unzipping Files with PHP
Google is your friend :)

Categories