• You are not logged in. | Login

Post a reply

January 17, 2007 10:01 am

IBdaMac
Member
Ranks

How can I resample the image?

I have the database with with images, say 640x480. There are no any problems with adding and outputting. I output all miniaturized images using  <image with=100> tag. Image lengh becomes 100 but its size isn't changed. It's ok when I upload 1-3 photoes, but if there 100 photoes there appears problems.


 

 

January 17, 2007 10:05 am

purplebean
Member
Ranks

Re: How can I resample the image?

There are a lot of ways out. Do you want to decrease it when upload to the server or you upload photoes by ftp? Take a program that will change the size automaticaly


 

 

January 17, 2007 10:27 am

bandlist12
Member
Ranks

Re: How can I resample the image?

Try that script:

<?php
if (eregi("^([a-zA-Z0-9]+)+.+([a-z]{3,4})+$",$_GET['file']) && file_exists("unix/path/to/pics/".$_GET['file'])) {
$filename = $_GET['file'];
list($width, $height) = getimagesize($filename);
$new_width = 101;
$new_height = $new_width;
 
$image_p = imagecreatetruecolor($new_width, $new_height);
 
$s = getimagesize($filename);
switch(strtolower($s['mime'])) {
case "image/gif": $image = imagecreatefromgif($filename); break;
case "image/jpeg": $image = imagecreatefromjpeg($filename); break;
case "image/png": $image = imagecreatefrompng($filename);break;
default: $image = imagecreatefromgif("http://mobibase.it/img/noimage.gif"); //change for smth yours.
}
 
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
$black = imagecolorallocate($image_p,89,140,173);
imagerectangle($image_p,0,0,100,100,$black);
header('Content-type: image/jpeg');
imagejpeg($image_p, null, 100);
} else {
die();
}
?>

 

 

January 17, 2007 10:29 am

bandlist12
Member
Ranks

Re: How can I resample the image?

Code: htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9]+)+.+([a-z]{3,4})+$ /previews/preview.php?file=$1

That's it.
Upload this to the previews folder and then print the image with the path  /previews/file_name


 

 

January 17, 2007 11:33 am

IBdaMac
Member
Ranks

Re: How can I resample the image?

bandlist12, thatnk you, I'll try this


 

 

January 17, 2007 11:36 am

IBdaMac
Member
Ranks

Re: How can I resample the image?

purplebean, no, I mean image which binaary code is stored in the MeSQL. I.e. get the code, transform it - get the little image and show it user and while resizing change it size in kilobytes


 

 

January 17, 2007 12:03 pm

bandlist12
Member
Ranks

Re: How can I resample the image?

Hmm, you store binary code in the MySql.....
So you'll have to modify my code for getting froma MySQL

It's better to store images as a single files


 

 

January 17, 2007 12:06 pm

IBdaMac
Member
Ranks

Re: How can I resample the image?

I found great function for this: imagecopyresampled(),
here ids the description http://us2.php.net/imagecopyresampled


 

 

January 17, 2007 12:08 pm

bandlist12
Member
Ranks

Re: How can I resample the image?

Did you find it?
I gave you the code where that function is pretty used unsure


 

 

January 17, 2007 12:13 pm

IBdaMac
Member
Ranks

Re: How can I resample the image?

With your help of course,
But here is another question: how can I insert the information from the database. I do as follows:

......
$getPhoto = mysql_fetch_object($result);
//body -binary information from the databse
$body = $getPhoto->body;
$filename = $body;
//pass the $filename variable $body content
?>

but script returns empty image. Where is a mistake?


 

 

January 17, 2007 12:14 pm

bandlist12
Member
Ranks

Re: How can I resample the image?

$filename is not the indicator to the file
try  $image = $body
but I am not sure


 

 
  • Actions
  • Top
ITCrimea. Ukraine Web Development Company. Professional Developers and Web Designers Team
Custom Web Designs, Internet Applications, E-Commerce Websites, Interactive Sites, Database-Driven Sites and Services