Solved

resolution change and croping image before uploading

Posted on 2004-04-28
13
1,632 Views
Last Modified: 2010-07-16
Does anyone have any code to change the resolution of a file as you upload it, so it automatically becomes 96dpi
Extra points will be awarded for anyone who can also provide code which can allow the image to be viewed and cropped first.

Thanks,
H
0
Comment
Question by:wjdashwood
  • 3
  • 3
  • 2
  • +3
13 Comments
 
LVL 6

Expert Comment

by:jkna_gunn
ID: 10940282
i think someone has asked this before, and they said you cannot change the resolution of file because resolution is related to how things are printed. does anybody know more??
0
 

Author Comment

by:wjdashwood
ID: 10940603
I'm pretty certain it can be done as part of resampling the image. I've seen an image resolution being changed before but only by copying the original image. I really could do with the code for cropping really though with it. This is now slightly more important than the resolution change.
If both parts can be answered a whole 500 pts will be awarded.
0
 
LVL 2

Expert Comment

by:Warble
ID: 10942927
resolution is device dependant. Most standard screens only display in 72 dpi.. some in 96.. printers usually print at about 300dpi or more.

If you take a 300x300 image, and print it, it will be one inch by one inch, if you display it on a 72 dpi screen, it will be about 4x4 inches.

See how it works? The file itself only displays suggestions for resultion. For example if you create a 300DPI image in photoshop, the file stores your 300 dpi recommendation, so that it can set zoom levels to make it seem as if it's 300pdi on your screen. The resolution isn't actually stored other than that. An image is just a certain number of pixels high by a certain number wide.

So, after all that, I think what you're asking is if there's a way to change the size of the image on the screen. You can do this a few ways, the GD library is very helpful in this respect, and I have had great luck with the imagick library, although it's not standard and kind of a pain to use due to lack of documentation.

Here's a PHP function to resize an image to a particular width/height:

You can get some great ideas by perusing the PHP docs in the GD section:

http://us2.php.net/manual/en/ref.image.php

More specifically:

http://us2.php.net/manual/en/function.imagecopyresized.php

The user comments have a few useful functions that you can copy and paste.

0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 2

Expert Comment

by:Warble
ID: 10942977
The code I posted didn't come out for some reason, but here's a link to a thumbnail generation class that's pretty helpful:

http://promoxy.mirrors.phpclasses.org/browse/package/1370.html


0
 
LVL 2

Assisted Solution

by:ElForesto
ElForesto earned 60 total points
ID: 10944402
This requires GD, but it's great for proportional resizes. It doesn't do any cropping, however.

http://testing.aplv.com/thumbs_inc.php.tar

Feel free to make whatever mods it takes for you to get the job done. The commands for cropping can probably be found in the GD documentation. As for previewing and selecting crop areas on the fly, you may need to use a Java applet to accomplish that. I suppose you could rig a system using imagemaps, but it would be terribly convoluted.
0
 

Author Comment

by:wjdashwood
ID: 10947702
perhaps what i actually want is a compression tool. Something that will keep the image size, but reduce the quality of the image, therefore reducing the filesize. I want this code to make it simple to upload image that have been taken from a digital camera, but make them websafe  for display on pages like ebay.
I already have the code for resizing images, but if theimage is already the right size, or the thing I have taken a photo of just appears in the middle of the shot I will need to crop and make it websafe. I know that screen resolution is 72 or 92 dpi which is why I asked for resolution change. These images will not be for printing out, just for viewing on screen.
0
 
LVL 6

Accepted Solution

by:
jkna_gunn earned 220 total points
ID: 10947756
0
 
LVL 2

Assisted Solution

by:Warble
Warble earned 220 total points
ID: 10950427
The user that views the photos will have a fixed resultion format that you cannot control. It might be 72, or 92dpi, but you can't do anything to the picture to alter that. It depends on the monitor itself.

If you're trying to optimize the size in bytes of the image, you can make some analysis of the image with GD and convert it to say a highly compressed Jpeg. It won't look all that great, but it will be small in size, but the same size physically.

Jpeg compression ranges from 1 to 100 (100 being no compression), and the standard jpeg is about 75. If you take this down to 50 or 60, you will get quite a noticeable size reduction. Below 50, and the image will look very poor, but it will get even smaller.
0
 

Author Comment

by:wjdashwood
ID: 10950549
thanks.
I think I will award points now. I will give some to warble for the explanation, and some to jkna_gunn for the link to the croping code.
Thanks,
H
0
 
LVL 2

Expert Comment

by:ElForesto
ID: 10952374
The functions I posted should allow you to specify the quality setting as well as the height, width, or both. I tweak it when I use the function to generate thumbnails.
0
 
LVL 1

Expert Comment

by:aahzman
ID: 11004522
If you really wanted to change the resolution (apart from resizing and cropping the image) then you can do this by using the 'convert' utility that's part of ImageMagick.  You would use a command (if I recall correctly) something like:

/usr/local/bin/convert -colorspace RGB -units PixelsPerInchResolution -density 72 "myfile.jpg"

which converts the image to RGB and gives it a resolution of 72dpi.

Andy
0
 

Expert Comment

by:1jaws
ID: 33223628
nope that didnt work...
0
 

Expert Comment

by:1jaws
ID: 33223632
Please disgread message above!!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question