Creating an image from an HTML document at runtime - php

I am currently working on a website project that requires the creation of an image based on user input on a form. Basically, I'm trying to create an image from existing HTML markup with the form data replacing some of text. The text is almost always unique.
I have explored several options for creating such an image, mainly:
imagecreate with PHP that wasn't flexible enough, and
PhantomJS which I can't really install on the server
wkhtmltopdf and php-wkhtmltox
I am working in a shared-hosting environment that limit my available options. The environment supports PHP (compiled with GD), Perl, and Python.
Is there a reliable way to implement such a behavior?

I use CutyCapt software to render images from html, it works perfectly. The only issue is that you need to build it on your shared hosting. Probably the workaround could be in building it on your local machine, uploading it to your hosting and running it from there, but I don't believe it will work, because it requires X server.
Another possible solution could be use of GD library to build the image manually. If you know how your html is looks like, you can replicate it by drawing all elements on a blank image. It is not easy to do, but looks like this is only one solution which you can use.

Related

Implementing color palettes using SASS on HTML - PHP web app?

I'm currently working as a front-end designer for a web financial application, and so far interface is working correctly, but now I have to make somehow possible for user to change interface main color pallete, and I would like to know if there is a possible way to send instructions from HTML or PHP to a .SCSS or .SASS file.
I'm currently using SASS on my local drive so the main color is $main: #0066FF; I compile it with PrePros and upload the CSS file to web hosting, but how could I make the value of $main variable on the SCSS file change when users desires? I found that Compass can make the recompiling process, but I'm still looking for a way to implement it on a CPanel hosting.
Another way I'm working around is using javascript to overwrite CSS classes but it is way too long and memory consuming. Any other suggestion?
Since I realized too late that even if it could be done, changing the SASS or SCSS file would alter its properties not only for the client, but also for the server, on which case all users would see the same changes and that's not what I intended. As Jeff stated, creating different CSS files and switching them via PHP or Javascript its the best way. Even using javascript or jQuery could work, but for my case there are too much elements that should change their values. Hopefully if anyone has had the same question should better reconsider if altering SASS files is an option.

Using Photoshop Actions on Images uploaded by Users

I want to have a user upload a image to my website and have a series of Photoshop actions like adding a layer behind of that image, a layer infront and some dynamic text with effects applied to it like drop shadow and gradient overlay. Is this even possible?
Have a look at Various Image Processing and Generation functions provided by PHP mainly ImageMagick & GD. If that does not prove to be sufficient,
Consider Gimp command line. you can easily invoke it from php using exec() function. GIMP is full featured & can do almost all fancy Photoshop actions you would want. And its free!
Hope it helps
PHP libraries are available to perform some basic graphics manipulation, as mentioned in the other answer. If these aren't adequate for you, it looks as though you can run and script the normal Photoshop program on your server. Photoshop is not available for Linux, so you'd probably need a Windows server. (This wouldn't be doable on shared hosting, you'd probably need a decent VPS at least.)
I haven't done this before, but according to Adobe Photoshop Scripting documentation your language choices are JavaScript and VBScript. Someone could write a PHP library to access this, but I don't know of anything like that.

Where should I put all these uploaded files?

I'm building a webapp that as a small subset of one of the features allows images to be uploaded. I'm running a lamp stack, with Mongo instead of MySql.
I use a javascript uploader with a php backend to upload the files. The whole framework is under version control though, so I don't want to dump these files anywhere inside my framework, as it would get messy with the version control, and sub-optimal when I eventually migrate the media over to a CDN.
So, my question is - On a VPS, where should I drop these images for now? In some folder external to my framework? In my DB as bson? I've heard Mongo does a decent job handling binary data...
And, as a follow up, if I'm eventually planning on moving the content over to a CDN, how would you recommend structuring my schema for now?
My current plan would be something like the following:
All uploads are named with a unique
ID and dropped in an external
folder, defined by a globally
accessible variable of sorts.
A reference to each images' name is
stored in the db.
Is there anything obviously stupid about going about it that way, possibly causing me a scaling headache later?
Here's a summarized specific question, just so this is a little more of an SO friendly question:
Given a Linux, Apache, Mongo, PHP Framework on a VPS, what is the best way to store uploaded images while keeping scalability and speed as the 2 most important factors in deciding on the solution?
if your plan is moving to CDN, the answer couldn't be more easy: create a subdomain on your VPS, and drop your images there, and you will have decent CDN simulation as well as reliable file storage.
I do agree that you should never put user uploaded content inside your webapp for many number of reasons but then one of the problem is how to show img tag in HTML which takes src attribute relative to webapp.
An easy workaround can be: Suppose create a folder /usr/ImagesUPloadByUser on your unix box and drop all images there. and then create a link ( linux link) in your webapp which points to correct directory. Now the images are not residing in ur webapp and you also have easy access .

turn web page into an image on the fly?

I was wondering if there was any way of turning an entire HTML page into a png (or other kind of image?) I'm trying to create PDFs on the fly, but it's pulling across my styles as text, but I want the styles to stay the same as the page (cufon and all). Any help would be appreciated! :)
This doesn't look straightforward. The backend (PHP etc.) doesn't do rendering, layout. It merely generates content.
The layout and visual aspects of the website are done by your client (browser) and the backend has no way of accessing this.
However, given an HTML file, there are libraries that can render it into a PDF like Prince XML that seem to be capable of this.
The only way to generate an image identical, or even near, what a visitor sees in their browser when viewing your site is to launch a browser and take a screenshot. You need the browser's rendering engine to render the page. All the libraries you find to do it without a browser create something much different than what the visitor sees, and won't render cufon or other fancy things at all.
Companies that offer screenshot previews of a webpage now run many servers, each running many virtual PCs, each running a full operating system and real web browser. They have all those systems pulling jobs, opening the webpages in real browsers, taking screenshots and saving images. You won't replicate that with a little PHP script.
http://ipinfo.info/html/rendering_services.php
Turning web pages into images and PDFs is a royal pain using PHP. Solutions often require OS level scripting, fake printer drivers, or screen capturing, which can make for a rather fragile setup. I ran into the same issue a few years ago and started working on native PHP extension that leveraged the Gecko engine to render HTML to PDF, but never finished it.
The best answer I've seen doesn't quite turn a full web page into a PDF, but instead does XML to PDF. XEP by RenderX is the commercial tool Apple uses to produce developer documentation in many formats, including HTML and beautifully rendered PDFs, from an XML source. The great thing about using the XEP tool in conjunction with PHP is that PHP deals with XML very well, so you can pass generated XML to the XEP binary, let it do the conversion to PDF, then deal with the resulting PDF file in PHP.
consider building a regular PDF file that resembles your web page:
PHP::PDF - constructing using php.
PDF Reference - file structure.

Linux-based MS Office thumbnail generation

I've been taken onboard to work on a PHP-based web application. One part of the application generates thumbnail images for MS Office documents on demand, and it uses MS Office + the VeryPDF docprint utility to do this. Because of this one requirement, the system is running on Windows Server 2003 + IIS.
I would prefer to have the system running on a Linux server, rather than MS, as I have far more experience in administering Linux systems than Windows and we have no other in-house technical staff.
Does anyone know a way to handle the document conversion using native Linux software? I would love something PHP native, but am willing to look outside that if necessary.
I have never done anything like this, so I'm just throwing an idea off the top of my head.
Have you thought about utilizing Open Office's capabilities to create thumbnail images? I know OO saves thumbnail images within a created document, so all you need to do is extract the image to display it. (This is demonstrated on the Ubuntu forums.) You could always do something sort of "hackish" where you use run a file through OpenOffice and extract the image to display a small thumbnail.
Again, I have no idea how well this will work, but it may be worth a shot.
To anyone else who comes across this, I have ended up going with the newer version of jodconverter. The sample code includes a basic web page that can be POSTed to using something like Pear's HTTP_Request2. A sample class (by yours truly) which uses this is mentioned in the comments in jodconverter's group on google code.

Categories