Image print quality check - php

Usual basic criteria for images in digital print are
CMYK
300 dpi
right scale
Is there a possibility to compare user uploaded image to placed print standard?
(Using PHP and perhaps some extension e.g. ImageMagic)
Idea is if user uploads bad print quality image e.g. jpg 100x100px # 72dpi notice user in proper way. But after all research I have made, couldn't define some model how to extract uploaded image data and do compare/check.
Any idea how to aproach this problem would be appreciated

You have Imagick::getImageResolution to get the resolution in dpi and you have getimagesize, there you check for the channels, 4 is cmyk, 3 rgb.

Related

php - optimize image file size

I'm making a web application for online comic. My biggest difficulty things are how to save the disk space when store the images (i don't have money ^^). I try to use GD2 to resize the image, convert to jpg, reduce the qualities...but the file size of each image still around 100kb.
For example: MY IMAGE with 650x900 px with some character, text.., no color, just black & white, the file size is 100kb.
But, when i making a NEW BLANK file with the same dimensions in photoshop and fill it all black (i think black color will make the file size more higher), then save on jpg, this new file size just only 8kb.
The question is, why the file size of MY IMAGE (with less black pixel) is higher than the NEW BLANK image with more black pixel? Is there anything inside the image source? And any solution to reduce the file size?
Thank all.
Basically question one is what format are you using.
I suggest you use PNG for black and white images. If it is possible use 1bit PNG.
Image compression i a complex thing. But no not the black pixels make the file size, but the variation of the pixels. But it is really a complex question.
see: http://en.wikipedia.org/wiki/Image_compression and http://en.wikipedia.org/wiki/Portable_Network_Graphics for some info on the subject.
For the best results if your images are currently JPEG-s then you need to apply somekind of noise reduction. For truly black-and-white (not grayscale) bumping up the contrast might help with that. Also strip out all meta information from the image.
One helpful tool to lower file size of images without reducing the quality is TinyPNG. This can cut the file size by up to about 80% without making any noticeable changes to the image itself. It has helped me to cut down my file sizes by an average of about 70%, and I hope it can help you too!

Retrieving a jpeg image over Facebook loses quality drastically.

I've been struggling to an issue of saving an image into jpeg which loses quality. As a project for my degree, I'm making an app where i upload the images on facebook.
I have a nice colored image, for which i shuffle the pixel values to get a mapped image. Then I upload it onto the facebook. When, i download and move the pixels back to original image, it loses the quality too much.
Below are the original, mapped and retrieved images:
I've tried many strategies like using png files, which works. But, currently, whatever the image is, facebook converts it to jpeg. So, if i upload maskedimage.png to facebook, it converts it to .jpg and loses some of the pixel-correlation values, which doesnt end up giving me the right image to retrieve original.
I'm using PHP and facebook-php sdk.
Please suggest.
Thank you
-Kaur
You're stuck. JPEG is a lossy algorithm which depends on human vision characteristics to mask the inaccuracies. By scrambling the pixels you've changed the nature of the loss so that it's not invisible anymore.
This isn't primarily about JPEG being lossy; it's about Facebook forcing image recompression, even if you check "High quality" when uploading.
The best you can do is to double the source image resolution, and for solid colors, try to introduce noise. Details in this GD.SE question
Note that the trick of uploading images <100kb has no longer been working, since at least June 2012.

php: Storing images in database

Currently i am using gd to converting the image uploaded in jpg with
imagjpeg($data,NULL,85)
and storing it in a blob mysql field. Problem is the quality. Yes the quality is just awful. A screenshot of a window with some text inside becomes pretty hugly. (While with a game screenshot the quality is passable)
Should I use other lib than GD?
Should I use other gd format? (imagepng?)
ps. please note: this is not a duplicate.. i am not asking how to save an img to db
ps2. note that if i should change my currently format/method I have to convert something like 5000-6000 images already stored as jpg in my db
ps3. i use 85 for imagejpeg, can't use a higher value because the image size would grow more than the original version
ps4. I need to store image in db, please stay in topic
Thanks all
================================
REFORMULATING THE QUESTION
I save image (mostly software screenshots, sometime games screenshots) in BLOB field after doing an imagejpeg($resourceFromImageCreateFromString,NULL,85);
Problem I am experiencing is the image uploaded looks pretty bad in confront of the original even if it's the same size. (sometime it gets bigger because of 85)
Is the imagejpeg implementations that sucks?
ps. my simple upload script does the follow calls:
upload file
open it with "rb" (binary)
pass the data to imagecreatefromstring
pass the result to imagejpeg
Thanks again
Is there a special reason you want to store your image inside a BLOB?
What quality argument did you pass to imagejpeg()?
You can set the quality of your output with the 3rd parameter to imagejpeg(). The problem is that JPEG is not the best format for images with a lot of text - you have to choose between turning down the quality and getting a lot of artifacts in your image, or turning up the quality and having a large file size. You might consider using PNG instead.
my first recommendation would be to try saving it as a png as the quality is better.
my second recommendation is to try the quality parameter in imagejpeg($image, $filename, $quality).
recommendation #3 - I worked on a site that I had to rewrite the image storage system because they implemented just what you are doing, storing images as BLOBs in the database. Their system only had about 20K images in it and it was crashing weekly because the database could not handle the load.
The conversion process for 5-6K images should not take more than a couple hours no matter how large the images. When I converted my images to disk storage from db storage, I ran 1K images at a time and each run took 5-10 minutes.
Why do you re-code anyway if it already IS a jpeg? To save space? Well, but then you already have your answer, in part - to save space from jpg to jpg you have to save in lower quality.
You cannot specify quality with imagecopyresampled, with imagejpeg you can. Use a high(er) value for the quality parameter.
Please note that JPEG is a format optimized for storing FOTOS. Images with large areas of the same color, straight lines etc. are much better stored in a lossless format like PNG. Of course, if you have a screenshot taken from a screen with fotos as desk background you have elements of both - so choose your format according to what you want. If the foto-part is more important and you don't care as much about fonts and lines, go with jpeg. Of course JPEG can be just as good quality as PNG for screenshots as well, but then you miss out on most of its compression capabilities, you have to use a 90+% quality setting. At 100% JPEG too is lossless, but by then a PNG might actually be of smaller (file)size.

How to define DPi for a new JPG image?

I'm going to create a new JPG image with PHP. How can I set the DBi value of a new JPG image.
Dirk
JPG is a Pixel format that doesn't really know physical dimensions like Dots Per Inch.
All you can do is write a dpi value into the file's Metadata as assistance for further processing, but it's just a recommendation and it can't be done using the GD library.
You would have to use an third-party library for this. See e.g. the second answer to this question: How do I add exif data to an image?

PHP JPEG Crop : Loss of quality?

I'm developing a web-to-print, poster printing application.
I'm considering using PHP to crop user-uploaded images, and we will ultimately print the PHP-cropped image.
My concern is there will be a difference in 'quality' between the original user uploaded image, and image after it is cropped by PHP.
Will PHP affect the quality of the image when handling it? Or does it preserve the image's quality and simply crop the relevant area?
Many thanks,
BK
JPEG is lossy compression. A bit of oversimplification, but it works by analyzing pixels around other pixels to see how similar they are. Not every pixel is stored, and that means it isn't possible to simply chop bytes out of the image data to perform the crop. If you are outputting JPEG, you will be re-compressing an already compressed image, and you will have some loss in quality. However, if you crop the image and your output is a non-lossy format, then you will not have loss of quality.
To be clear, the loss of the quality isn't in the crop operation. It is in the way the image is compressed itself. If the source image is compressed with JPEG, quality has already been lost. When you crop that image, you aren't losing anything more, but if you were to output JPEG again afterwards, this would require a re-compression, and thus more loss.
So in the end, make your final output PNG or something non-lossy and you have nothing to worry about.

Categories