Can I convert all files with jquery file upload to jpg? - php

I'm using the jquery file upload script and it's working really well so far. The last obstacle I have is I only want to use jpg images for my website but allow users the option of uploading gif, png, or jpg.
I'm assuming I need to alter or add some additional methods to the upload.class.php file to accomplish this.
Has anyone done this before and if so is this the correct file to modify?

You will need to write some pretty tough conversion functions if you want to implement it in pure JavaScript and you'll be limited to modern browsers that support FileAPI and FileReference. Also the conversion function you'll have to write would manipulate the files at the binary level and will have to respect some pretty strict file structures as specified by GIF/JPEG/PNG standards specifications.
As i recall SWFUpload (a Flash - ActionScript - JavaScript library) has this functionality embedded, you can specify the format in which it should send the file to the server but it only applies if you wish to use the resizing function which sends a resized version of the original file to the server but it has some downsides.

Related

Converting HTML to images without installing anything

I want to create a functionality that converts HTML source code of some websites into jpg/png images. I also have to do that on external server - which means I don't know if it has all necessary libraries, and I don't wanna install there too much things, the less the better.
I have found two options:
- wkhtmltoimage
- cutycapt
But they both require dependencies to install, not to mention emulating server, which sucks.
Is there a way to do this without any external libraries? Thanks!
This is very much possible in linux using pbmtext. This tool converts any text into a pbm image file.
For you case,
curl -L google.com | pbmtext > google.pbm
However, beware that this will produce a very large file (several 100s of MB). So you will have to do some post-processing, like converting it into another format or resizing it.
You can use this Java Library, Html2Image.This simple Java library converts plain HTML markup to image and provides client-side image-map using HTML element and also supports different image formats such as GIF, PNG or JPEG image.
This library has very handy, simple and sober API's.
Common usage is this:
HtmlImageGenerator imageGenerator = new HtmlImageGenerator();
imageGenerator.loadHtml("<b>Hello World!</b> Please goto <a title=\"Goto Google\" href=\"http://www.google.com\">Google</a>.");
// OR you can fetch HTML from URL
imageGenerator.loadUrl("http://www.example.com/xyz.html");
imageGenerator.saveAsImage("hello-world.png");
imageGenerator.saveAsHtmlWithMap("hello-world.html", "hello-world.png");
Which will generate hello-world.png image of the HTML and hello-world.html file containing client-side image-map .
There are several others API's of this library which you can explore as per your needs.

set swf scalemode to showall using swf library or php

I have a lot of swf files that have the Stage.scaleMode property set to noscale. When embedding the videos they do not scale at all (which would be expected).
I am looking for a way to programmatically change the scaleMode to showAll in my swf files. Ideally I would like to process a swf file using PHP and alter the file. Otherwise some kind of swf library would be nice.
So my question would be is there an easy way to open a swf file in binary mode, jump to the part of the swf file where it stores the scaleMode and alter the file using PHP? Or, is there a swf library that can do it for me?
All swf files are scalable.. its the configuration you put it on the page with which decides its scale mode. but you can easily override it by changing the scale property, in the html you use to include it with. Atleast. since you want to use php to get the job done, i tought you are making a website:
you can set an property scale. Which has 4 diffirent modes : default, exactfit, noborder and noscale
If this is for some reason not possible, you could concider using the ming library in php. But the scale property in html should always be prefered over altering the swf file

Detect image resolution?

I've made some research and couldn't find the answer. Is it possible to detect an image resolution using an upload file field?
Right now, I can detect the size of an image in pixels...But I would need it to find the "inches" size.
And I also need to find out the resolution of the image.
Using Javascript would be the best...if possible, if not...PHP maybe?
Thanks!
You'll have to do this once it has been submitted. Check out the getimagesize function in PHP - http://php.net/manual/en/function.getimagesize.php
You will need a browser that supports the FileReader interface - read more at Is it possible to get info from a file on the client side without uploading the file?.
There are some javascript libraries reading such information like EXIF from the file:
JsJpegMeta
ImageInfo - although I'm not sure whether it gets its binary data by ajax from already uploaded files.
If you want to offer this functionality to user with browsers not supporting this, you will need to upload the file and do it serverside (with PHP).

Is there a way with PHP to access a file on a server and save only the first half of the file?

I want to give users a preview of certain files on my site and will be using scribd API. Does anyone know how I can access the full file from my server and save the file under a different name , which I will then show to users..Can't think of a way to do this with PHP for .docx and image files...Help is much appreciated.
For "splitting" images, use an image processing library like gd to crop the image (lots of examples to be found on how to do that all over the place). For Word documents, use a library like PHPWord (or one of the other myriad such libraries) to open the document, remove/extract as much text as you need, then save that into a new Word file.
For other file types, find the appropriate method that allows you to manipulate that format, then do whatever you need to do with it.

Display Illustrations created in illustrator

I am trying to create a web application where designers can submit and share there work. But i figured not all designers would submit only jpeg's or gif's. So i am allowing options to submit their creations in .ai (Adobe Illustrator) format. But after the file is uploaded can i give any options to the users to view those illustrations. Is there any external application which i can use to give preview of such files.
I am developing in PHP, and using CakePHP
They can save their files as SVG, which is a vector graphics file that won't loose quality on zoom.
Modern browsers can display SVG file, Wikipedia seems to use them a lot : http://fr.wikipedia.org/wiki/Fichier:SVG_Simple_Logo.svg
ImageMagick seems to have support for .ai
http://www.imagemagick.org
Illustrator natively has the ability to save as a PDF.
The challenge with users submitting an .ai file is you can have many versions of the same design or document with varied layer combinations within the same document and endless combinations of these across various artboards (which can all be different sizes within the same document). I don't think doing this well is a matter of simply being able to display a certain file format or a preview of the document. As above I think it would be better to utilise other formats such as PDF, SVG or just make it simpler and educate them through the UI to save comps as PNG/JPG/SVG etc and make the ai available for download.

Categories