Gum can u please send me the file in ur script to resize images... its the one u use to keep all the bbcode images the same size. i need it to make all the images in my user gallery the same size. plz
Need Code To Modify Image
Collapse
X
-
lamar-wap
meet me on yahoo i can send it to you................Gum can u please send me the file in ur script to resize images... its the one u use to keep all the bbcode images the same size. i need it to make all the images in my user gallery the same size. plz[/b]
-
Code:<?php // The file $filename = 'test.jpg'; // Set a maximum height and width $width = 200; $height = 200; // Content type header('Content-type: image/jpeg'); // Get new dimensions list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // Resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); // Output imagejpeg($image_p, null, 100); ?>
Comment
-
thanks gums. now how do i use that to resize the images in the gallery?[/b]Code:<?php // The file $filename = 'test.jpg'; // Set a maximum height and width $width = 200; $height = 200; // Content type header('Content-type: image/jpeg'); // Get new dimensions list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // Resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); // Output imagejpeg($image_p, null, 100); ?>
Comment
-
Guest -
Guest -
Guest
I guess you can, by changing the content type...thanks Gums. it works on jpg images. can i modify the content type so it also resises .gif and .png formats?[/b]
Code:header('Content-type: image/jpeg');
Comment
-
lamar-wap
yes wizard you can i was using it once in my script but i will add it back soon when i get the time.
Comment
-
Regz
ma image file is $photo how to resize tht ? ...here is code of user.php where $photo i need resizedCode:<?php $r=rand(0,100000); header ("Content-type:text/vnd.wap.wml; charset=utf-8"); print '<?xml version="1.0" encoding="utf-8"?>'; print '<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"'. ' "http://www.wapforum.org/DTD/wml_1.1.xml">'. '<wml><head><meta http-equiv="Cache-Control" content="no-cache" forua="true"/></head>'; include "./ini.php"; $login = autorize(); if($search) { $query_users = @mysql_query("select * from `".$px.$utable."` where login='".$dblogin."';"); $data = @mysql_fetch_array($query_users); } else { $query_users = @mysql_query("select * from `".$px.$utable."` where id='$dbid';"); $data = @mysql_fetch_array($query_users); } print '<card title="'.$data['login'].'">'. ' '; if($login) { $moder=$login['moder']; $admin=$login['admin']; $from=$login['email']; $user_moder=$data['moder']; $to=$data['email']; $photo=$data['photo']; $status=$data['status']; if(!$search) print '<input name="msg'.$r.'"/> '. '<select name="private" title="'.$lang['privat'].'">'. '<option value="0">Public</option>'. '<option value="'.$login['id'].'.'.$data['id'].'">Private</option>'. '</select> '. '<anchor>'.$lang['say'].'<go href="room.php?id='.$id.'&pass='.$pass.'&room='.$room.'&r='.$r.'&mod='.$mod.'" method="post">'. '<postfield name="private" value="$(private)"/>'. '<postfield name="msg" value="'.$data['login'].', $(msg'.$r.')"/>'. '<postfield name="translit" value="$(translit)"/></go></anchor> '; if($login['fsize'] == "small") { $fsize1 = "[size="1"]"; $fsize2 = "[/size]"; } elseif($login['fsize'] == "big") { $fsize1 = "<big>"; $fsize2 = "</big>"; } else { $fsize1 = ""; $fsize2 = ""; } print $fsize1; if($data['sex']=="m") { $sex = "Male"; } else { $sex = "Female"; } if(!empty($photo)) { print $lang['nick'].": <a href=\"$photo\">".$data['login']."</a> "; } else { print $lang['nick'].": ".$data['login']." "; } print "<a href=\"letters/sendform.php?id=$id&pass=$pass\">".$lang['sendpm']."</a> "; print $lang['name'].": ".$data['name']." "; print $lang['sex'].": $sex "; print $lang['live'].": ".$data['live']." "; $browser = explode (" ", $HTTP_USER_AGENT); $browser = $browser[0]; $phnupdated=mysql_query("UPDATE chat_users SET mobile='".$browser."' WHERE id='".$id."'"); print $lang['phone'].": ".$data['mobile'] ." "; print $lang['operator'].": ".$data['operator'] ." "; print "e-mail: <a href=\"email.php?id=$id&pass=$pass&room=$room&to=$to&from=$from\">".$to." </a> "; print $lang['wap'].": <a href=\"".$data['wapsite']."\">".$data['wapsite']."</a> "; print $lang['web'].": <a href=\"".$data['website']."\">".$data['website']."</a> "; print "ICQ: ".$data['icq']." "; print $lang['status'].": $status "; print $lang['posts'].": ".$data['posts']." "; print $lang['about'].": ".$data['about']." "; print $lang['datereg'].": ".date("d-m-Y", $data['rtime'])." "; if(!empty($moder)&&empty($data['admin'])) print "[b]:::[/b] <a href=\"moder.php?id=$id&pass=$pass&whoid=$dbid&room=$room&mod=kick\">".$lang['kick']."</a> "; if($moder>=2&&empty($data['admin'])) print "<a href=\"moder.php?id=$id&pass=$pass&whoid=$dbid&room=$room&mod=kill\">".$lang['kill']."</a> "; if($moder>=3&&empty($data['admin'])) print "<a href=\"moder.php?id=$id&pass=$pass&whoid=$dbid&room=$room&mod=agent\">Browser</a> "; if(!empty($admin)) { if($user_moder>=1) { print "[b]:::[/b] <a href=\"admin.php?id=$id&pass=$pass&whoid=".$data['id']."&room=$room&mod=delmoder\">".$lang['delmoder']."</a> "; } else { print "[b]:::[/b] <a href=\"admin.php?id=$id&pass=$pass&whoid=".$data['id']."&room=$room&mod=makemoder\">".$lang['makemoder']."</a> "; } if($user_moder>=2) { print "<a href=\"admin.php?id=$id&pass=$pass&whoid=".$data['id']."&room=$room&mod=delkiller\">".$lang['delkiller']."</a> "; } else { print "<a href=\"admin.php?id=$id&pass=$pass&whoid=".$data['id']."&room=$room&mod=makekiller\">".$lang['makekiller']."</a> "; } if($user_moder>=3) { print "<a href=\"admin.php?id=$id&pass=$pass&whoid=".$data['id']."&room=$room&mod=delshpion\">".$lang['delshpion']."</a> "; } else { print "<a href=\"admin.php?id=$id&pass=$pass&whoid=".$data['id']."&room=$room&mod=makeshpion\">".$lang['makeshpion']."</a> "; } if($user_moder>=4) { print "<a href=\"admin.php?id=$id&pass=$pass&whoid=".$data['id']."&room=$room&mod=deltopmoder\">".$lang['deltopmoder']."</a> "; } else { print "<a href=\"admin.php?id=$id&pass=$pass&whoid=".$data['id']."&room=$room&mod=maketopmoder\">".$lang['maketopmoder']."</a> "; } print "<a href=\"admin.php?id=$id&pass=$pass&whoid=".$data['id']."&room=$room&mod=del\">".$lang['delete']."</a> "; } print "[b]:::[/b] <a href=\"ignor.php?id=$id&pass=$pass&room=$room&r=$r&mod=set&whoid=".$data['id']."\">".$lang['in_ignor']."</a> "; if($room) print "<a href=\"room.php?id=$id&pass=$pass&room=$room&r=$r\">".$lang['to_chat']."</a> "; else print "<a href=\"enter.php?id=$id&pass=$pass&r=$r\">".$lang['holl']."</a> "; print $fsize2; } else { print $lang['access_denied']; } print '</p>'. '</card>'. '</wml>'; @mysql_close(); ob_end_flush(); ?>
Comment
-
Simplified Image Resizing with PHP
By Greg Knox
April 17th 2003
Reader Rating: 6.1
If you're anything like me, you're probably lazy (and if you're not, give yourself a pat on the back!).
Recently, as I built a Website to show off a range of products, I realized that not only was I going to want to use the same product image over and over again, but I was going to want to use that same image at different sizes throughout the site!
I thought to myself, "I don't feel like having 4,000 different thumbnails on my server for each product, and I don't want to have the image look all jacked-up and distorted if I hard code the image width and height in my HTML [1]".
I know what you're thinking. Why couldn't I just use something like ImageMagik [2]?
In most cases, I would use ImageMagik so that I could have a regular version and a thumbnail version of each image. But in this particular case, I wanted to be able to display various sizes of the same image, without having 4,000 different thumbnails sitting around taking up space.
So how did I do it? Well, I improvised. I knew these things:
I wanted one image per product.
I wanted the size of the altered image to keep its aspect ratio, no matter whether it was landscape or portrait.
I wanted one script to do all of this dynamically.
So, with the knowledge I'd gained using PHP [3] almost on a daily basis, I sat down and started figuring out a function to achieve these goals. I am by no means a PHP guru -- in fact, I taught myself the language sometime in the summer of 2002, so by most standards, I'm still a newbie. But I thought I could create a script that would do exactly what I wanted...
Getting Started
Let's say you have a great line of socks that you want to sell through your site. Well, you're proud of these fantastic socks and want people to see as much of them as possible: on the product views page, on the search page, on the listing page, etc. But this doesn't mean that you have to use the default image size each time, nor risk the quality of the image being degraded when it is stretched or crunched into a space. Some socks are longer than others and so you might have the image sizes ranging from 200x400 up to 600x750 pixels.
To begin writing the function, we have to declare it as such... Then we have to throw in our attributes. We want to restrict our image, so we have to let the function know the dimensions to which we want to restrict it, and we have to know what the original image size is to begin with (we'll get to that part in a second).
<?php
function imageResize($width, $height, $target) {
//takes the larger size of the width and height and applies the
formula accordingly...this is so this script will work
dynamically with any size image
if ($width > $height) {
$percentage = ($target / $width);
} else {
$percentage = ($target / $height);
}
//gets the new value and applies the percentage, then rounds the value
$width = round($width * $percentage);
$height = round($height * $percentage);
//returns the new sizes in html image tag format...this is so you
can plug this function inside an image tag and just get the
return "width=\"$width\" height=\"$height\"";
}
?>
Before we take our new function on a test drive, we need to get the width and height of the image that we want to display. There is a magical command in PHP called getimagesize() [4]. This command, used properly, will return the image width, height, type, and even the width and height in HTML image tag format (width="x" height="y").
$mysock = getimagesize("images/sock001.jpg [5]");
Now, $mysock is an array [6] that holds vital information about the particular image we want to display. In index 0, we have the width ($mysock[0]), and in index 1, we have the height ($mysock[1]). That's really all we need, in order to get what we want done. Want to see the function... well, function? Here we go!
The Function in Action
Let's say you want to display a list of your beautiful socks, but you want room on the page to show them neatly in a row, and to do that they cannot be larger than 150 pixels tall or wide.
<?php
//get the image size of the picture and load it into an array
$mysock = getimagesize("images/sock001.jpg");
?>
<!-using a standard html image tag, where you would have the
width and height, insert your new imageResize() function with
the correct attributes -->
[img]images/sock001.jpg[/img]>
That's it! Now, no matter what the original file size, it will be restricted to no more than 150 pixels in width or height (or whatever you specify).
Now, you may think "This sounds too good to be true. Is there any circumstance where using this technique could prove disastrous?"
Actually, there is. Keep in mind that you aren't changing the file's original size. That same 200x400, 50 KB picture you uploaded only moments ago is still 200x400, 50 KB. This script only changes height and width attribute in HTML, so that your original picture conforms to the height and width you think will look best on your Web page.
Having said that, if you have a page that lists 50-something products, the page will display the way you want it to, but uses will have to download all 50 of those 50 KB pictures, which could take some time. So I'd have to recommend this technique in situations where you're only showing a few pictures at a time.
Comment
-
Regz
Ammm bro i have read tht in ua old post too the script i said to u to integrate image resize into isnt allowing this to be add up i tried i l try agn cos u have given a particular image name to be resized in script i gave its $photo tht needs to be resizedthe $photo is variable how to resize it i have no clue the echo code shud have image resized nd the print code above shud show original image thts wht i want if m clearCode:if(!empty($photo)) { echo "<img src=\"$photo\" alt=\"\"/> "; print $lang['nick'].":<a href=\"$photo\">".$data['login']."</a> ";
Comment


Comment