pro_php thread: jpg image resizing...
Hi!
I'm a "semi-pro" php programmer and my recomendation is javascript instead
of php because its ease your work later belive me and you will see.
Just put the script after the <img..> tag like this
<script change_pic( i1, "<? echo $image_file_name; ?>, 100, 0, 1 )
</script>
Better if you generate the page from php engine:
.
.
.
printf("<img name=\"%s\" src=\"%s\">", $img_obj_name, $img_file_name);
printf("<script>"
printf("change_pic( %s, %s, %d, 0, 1)", $img_obj_name, $img_file_name,
100 );
printf("</script>");
.
.
.
Here's the script:
where
-img_obj = image object's name
-path = image file name to show
-max_size = maximum horizontal or vertical size of the image
-border = 1 means draw a border, 0: don't
-show = 1: show the image, 0: don't
function change_pic(img_obj, path, max_size, border, show) {
if( path.length == 0 )
return;
if(show==true) {
orig_img = new Image();
orig_img.src = path;
zoom = 1;
if(orig_img.width > max_size)
zoom = max_size / orig_img.width;
else
if(orig_img.height > max_size)
zoom = max_size / orig_img.height;
img_obj.width = orig_img.width * zoom;
img_obj.height = orig_img.height * zoom;
img_obj.src = orig_img.src;
img_obj.border = border;
}
else {
img_obj.src = "";
img_obj.width = 0;
img_obj.height = 0;
img_obj.border = 0;
}
}
Bye, i hope it's helpfull