Hi, new to the group.
I use the following code to resize images my users upload. They're
either blurry or they're jaggy.
Can someone recommend modifications or different code that will resize
images smoothly?
$o_file = $_GET['add'];
$image_info = getImageSize($o_file); // see EXIF for faster way
switch ($image_info['mime']) {
case 'image/gif':
if (imagetypes() & IMG_GIF) { // not the same as IMAGETYPE
$o_im = imageCreateFromGIF($o_file);
} else {
$ermsg = 'GIF images are not supported<br />';
}
break;
case 'image/jpeg':
if (imagetypes() & IMG_JPG) {
$o_im = imageCreateFromJPEG($o_file);
} else {
$ermsg = 'JPEG images are not supported<br />';
}
break;
case 'image/png':
if (imagetypes() & IMG_PNG) {
$o_im = imageCreateFromPNG($o_file);
} else {
$ermsg = 'PNG images are not supported<br />';
}
break;
case 'image/wbmp':
if (imagetypes() & IMG_WBMP) {
$o_im = imageCreateFromWBMP($o_file);
} else {
$ermsg = 'WBMP images are not supported<br />';
}
break;
default:
$ermsg = $image_info['mime'].' images are not supported<br
/>';
break;
}
if (!isset($ermsg)) {
list($width, $height) = getimagesize($o_file);
if($width>200){
$t_wd = 200;
$t_ht = round(($t_wd / $width) * $height);
$t_im = imageCreateTrueColor($t_wd,$t_ht);
imagecopyresampled ($t_im,$o_im,0,0,0,0,$t_wd,$t_ht,$width,$height);
imageJPEG($t_im);
imageDestroy($t_im);
}else{
imageJPEG($o_im);
imageDestroy($o_im);
}
}
?> 1 5942
Geuis wrote:
Hi, new to the group.
I use the following code to resize images my users upload. They're
either blurry or they're jaggy.
Can someone recommend modifications or different code that will resize
images smoothly?
$o_file = $_GET['add'];
$image_info = getImageSize($o_file); // see EXIF for faster way
switch ($image_info['mime']) {
case 'image/gif':
if (imagetypes() & IMG_GIF) { // not the same as IMAGETYPE
$o_im = imageCreateFromGIF($o_file);
} else {
$ermsg = 'GIF images are not supported<br />';
}
break;
case 'image/jpeg':
if (imagetypes() & IMG_JPG) {
$o_im = imageCreateFromJPEG($o_file);
} else {
$ermsg = 'JPEG images are not supported<br />';
}
break;
case 'image/png':
if (imagetypes() & IMG_PNG) {
$o_im = imageCreateFromPNG($o_file);
} else {
$ermsg = 'PNG images are not supported<br />';
}
break;
case 'image/wbmp':
if (imagetypes() & IMG_WBMP) {
$o_im = imageCreateFromWBMP($o_file);
} else {
$ermsg = 'WBMP images are not supported<br />';
}
break;
default:
$ermsg = $image_info['mime'].' images are not supported<br
/>';
break;
}
if (!isset($ermsg)) {
list($width, $height) = getimagesize($o_file);
if($width>200){
$t_wd = 200;
$t_ht = round(($t_wd / $width) * $height);
$t_im = imageCreateTrueColor($t_wd,$t_ht);
imagecopyresampled ($t_im,$o_im,0,0,0,0,$t_wd,$t_ht,$width,$height);
imageJPEG($t_im);
imageDestroy($t_im);
}else{
imageJPEG($o_im);
imageDestroy($o_im);
}
}
?>
Have a look at http://uk.php.net/manual/en/function.imagejpeg.php -
imagejpeg() has a third parameter for quality. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ruby Tuesday |
last post by:
I have a section(185pixelsx 185pixels) in my web page to display an image
that is stored in a directory. Using php, how do you resize so if:
the image dimension is smaller(width and height is...
|
by: nawfer |
last post by:
for to resize and copy original photos into a new directory and to use
for a thumbnail gallery on the web;
what is better: GD, Netpbm or imagemagick and why?
very thank
|
by: Neil Woodvine |
last post by:
***Scenario ...
I have a DataList with a hyperlink WebControl in the Item Template.
I want to display a 64x64 image in the Hyperlink and set the NavigateURL to
the full size image.
***Source...
|
by: Zahid Khan |
last post by:
I need little help in my situation.
I am reading a graphic file (jpg) from disk and then
resizing it and save resized image. What happens, it gets
blured, I want to retain same quality so that...
|
by: Tim T |
last post by:
Hi,
Could someone please point to to a tutorial / code for dynamically resizing
images on upload, THEN saving to disk on the webserver.
I need users to be able to upload images to my server, but...
|
by: Daniel |
last post by:
I have looked everywhere on the web for an answer to this and the only
thing I can find is converting the image format when the file is
present on the local filesystem. What I want to do is use a...
|
by: tshad |
last post by:
Is there a way to display images (imageButtons or linkbuttons for instance)
as a max size (200px by 50px) and not have it stretch the image?
What I want to be able to do is limit the real estate...
|
by: kombu67 |
last post by:
I'm reading a series of images from a MS SQL table and saving them to
directory. These are staff ID pictures from our security card app.
Once I've extracted the ID photo from the security app to...
|
by: mishrarajesh44 |
last post by:
hii all,
I am facing a problem currently..
i have a script for image uploading and resizing..
the image uploading takes place properly for every size images..
but, the resizing works for...
|
by: anfetienne |
last post by:
hi.....i have this script (below #1) that is linked to another php file SimpleImage.php (#2) im trying to get it to work on my uploaded images but it keeps coming up errors.....i haven't altered...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |