Create Vector Image in PHP to Allow Upscaling - php

This question is slightly long, so I'll try to be clear.
On a website I co-develop, I created a drawing application that sends data about the lines drawn on the <canvas> element to the server to create an image and save it at multiple sizes, which works. There is the standard save which is saved to 320x212, with the smaller version at 240x176.
However, some users on my site use a pretty antiquated device/browser for the application. It also has a smaller viewport, so the image is smaller, so server-side I'm currently multiplying the coordinates to compensate when saving the image to the standard size. But this has the side-effect of random unfilled parts of the image showing up, that were filled in on the canvas.
(source: socialcu.be)
(On the canvas for the smaller device's viewport, the entire bottom portion was green, while my method of multiplying the coordinates to compensate caused many unfilled portions to appear on the scaled-up image)
So my first question is, would making the image as a vector image, scaling it up (while still a vector), and then saving it as a raster image fix that issue?
And secondly (if the answer to the first is a yes), then what would be the best way of doing this in PHP? I've heard of Cairo, but the information on it (namely tutorials for the PHP package) is quite lacking. Optimally, is there a way to do this in Imagick, or a tutorial on how to use Cairo?

Cairo is definitely lacking for documentation on the PHP site, so it will be a much more difficult set to learn. I found a couple of links through Google in regard to Cairo. There is a blog post about someone's experience with it here: Getting started with Cairo
Referenced in that post are a couple of walk-thrus by Michael Maclean.
There are quite a few examples of drawing with imagick on the imagick website, and from the looks of the available research online with examples imagick has a better support community (for now). imagick will output a raster image though.

Related

Image resize, resample, maintain ASPECT RATIO and ORIENTATION, thumbnail generation using php

I am building a website using
php 5.3,
Twitter Bootstrap
MySQL,
Which includes a few features where registered users can create their own profile, upload avatar, cover photo, update status, share photos etc.
Since I am a newbie to all the 3 technologies mentioned above I rely completely on the internet to get my job done. Right now I am having trouble in resizing, re-sampling and maintaining aspect ratios and orientation of the uploaded images using GD library.
My expectations are:
Reduce the file size of images while maintaining the quality and aspect ratio.
Maintain orientation [many images are rotated horizontally, something to do with exif I guess].
Generate 4 different sized thumbnails [30x30, 40x40, 55x55 and a large one for cover pic].
I tried many options, but haven't found a single solution which does all of this. I came across ImageMagick library which looks promising, but not sure whether it serves my purpose. Please help me with code snippets or examples related to my requirements.
P.S. If in case my question was not clear, I am trying to achieve image manipulations like Facebook and Twitter do.
Thanks in advance
My answer will not solve your problem,but will help you to know something else.You can minifiy your image size (up to 80%) and keep you images with that size.Here is a tool which you can check out.http://www.w3docs.com/tools/minimage/

given two images, determine whether one is edited from the other (and which is the original)

suppose there is an image on web without watermark. And someone downloads it and makes some edits on it like adding watermark etc etc. Is it possible to write a script in php to compare these two images. Like when I submit these two images to the script, it should be able to output the original image and manipulated image.
I read google's webmaster page which says
Google often finds multiple copies of the same image online. We use many different signals to identify the original source of the image
Blockquote
This is the main concern of my question
One more doubt is will there be any meta tags inside an image. if at all how to read them. Is it possible to edit them. Are there any information(not visual) inside an image which cannot be edited.
Anything within the image can be edited (it is, after all, just a collection of bytes), and it's definitely trivial for someone to add a watermark to an image, or simply change the contrast ever-so-slightly, to make it a very different file from the original. There are several other non-destructive changes that would make image files look completely different to a naive comparison algorithm (e.g., scaling, changing filetypes and compression, changing brightness, rotation, etc.).
Advanced image processing algorithms, however, can still often identify similarities between images that have been manipulated in ways like those above. There are many algorithms to do this, and honestly you could spend thousands of hours trying to roll an algorithm like this yourself. These sorts of algorithms are referred to as "content-based image retrieval."
You might be better off calling into engine that's already been developed to do exactly this. Here are some possibilities:
TinEye has a RESTful API that you can use, described here.
You could scrape the response from Google's Search by Image results using this technique.
You could use any of the number of suggestions within this slightly older StackOverflow post.
Good luck!
Photos taken by digital cameras usually have exif data embedded.
You can get the data with the exif_read_data function in PHP.
As for identifying similar images, here's some useful resources:
TinEye
SO Q on image similarity
The comments on Resig's article
You could submit both images to ImageEdited and see which one has been edited. Even if the exif data's missing, it tells when an image has been created with a program.

automatic cropping of images according to height width given in img tag

In my website on listing pages I have to show small thumbnail of images which are used in detailed pages and they are larger in size. SO to display thumbnail in listing i am scaling them with height and width in <img> tag.
I know this is never good idea. because it makes page heavy and it takes time to load.
Is there any way that images get automatically cropped according to given height width ?
If you have PHP available, you can try phpThumb, which does all that for you and much more. It can crop, zoom-crop, transform, blur, contrast...etc etc, and it auto-creates the thumbnails and keeps them in cache so it doesn't have to re-crop...etc each time the image is loaded.
It's also VERY simple to install and use, which is a big plus.
You can't crop things client-side to make them lightweight because all the heavy lifting is already done (transferring the files). Not to mention it would be very intensive for your end users to be doing image manipulations. You will need to create thumbnails server side. You should post a question detailing what server side technology you are using (C#, php, etc). Ideally you would cache them or create them ahead of time so that you only do it once and save your server from unneeded work too.
Actually, don't post a followup question on what server side tech you are using. This has been asked a ton of times on SO. Search for how to do it. php thumbnail creation for example.

Zend PDF image bad quality

I've tried Zend PDF and it works pretty well but I have a troublesome problem : when I add an image to a page with drawImage() it always appears pixilated regardless position and dimensions.
There's many lines I don't understand in the Zend images classes, has someone already encountered this problem?
How can I fix this ?
(I cannot post my code today but it's very simple and I think my question is not specific)
Remember that PDF is inherently a print medium (300dpi and higher), while your average .jpg is intended for screen viewing (72-100dpi). If you don't supply source images with approximately the same resolution as the document you're inserting it into, the PDF display engine will have to do all kinds of scaling to make things fit. Once when you insert the image to stretch it out to the size you want, and then downscaling again to make the PDF fit on your screen.

Recognize image with PHP

I run a site with lots of small images (www.iconfinder.com) and would like to develop a feature that can compare and recognize images. A user should be able to upload an image (icon) and then the site will respond with information about the image if it's in the database.
What is the approach to finding similar (or the same image). I know I can compare md5 of the two images, but I also want be able to find matches if the are scaled.
This is a good start if you are interested in looking at doing it in PHP:
http://www.intelliot.com/blog/2008/03/sorted-directory-listing-image-resizing-comparison-and-similarity-in-php/
There probably aren't a lot of languages LESS suited to this task than PHP. You should really look for an image comparison library with a C compatible API and figure out how to glue that into your PHP application.
Identical images can be checked with an md5sum, but detecting if somebody uploads a scaled image, which displays the same thing as the other is very hard. This requires digital image processing.
An approach is to scale down all images to a certain width (say 100px). Then check a few coordinates for the color. If another image matches a big part (say 80%), it might be the same image.
But if the image is lighter... this won't work.

Categories