Re: Resizing an image (dynamic)

From: Date: Sun, 03 Dec 2000 08:37:33 +0000
Subject: Re: Resizing an image (dynamic)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-28414@lists.php.net to get a copy of this message
try this code snippet, this is designed for a file on disk but this should help function thumb($image,$divider=4,$quality=70) { // If someone tries to change directories, bomb out if(ereg("/", urldecode($image))) { die; } Header("Content-type: image/jpeg"); $imagefile = "images/".urldecode($image).""; $src_img = imagecreatefromjpeg($imagefile); $new_w = imagesx($src_img)/$divider; $new_h = imagesy($src_img)/$divider; $dst_img = imagecreate($new_w,$new_h); imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img)); imagejpeg($dst_img,'',$quality); ImageDestroy($dst_img); ImageDestroy($src_img); } Lauri Vain wrote: > Hello, > > I have to resize an image to reduce the loading time (there will be thumbnails, > which have to be resized, and there will be full sized images). > > Now, the images that will be inserted into the DB have the dimensions height=300 > and width=400. The dimensions for the thumbnail have to be 4 times smaller. > > /************ code to show images **************/ > <?if (!isset($id) || empty($id)) { > echo "Looking for images ?"; > } else { > $mysqlhost = "localhost"; > $mysqluser = "**********"; > $mysqlpassword = "*******************"; > mysql_connect($mysqlhost, $mysqluser, $mysqlpassword) or die > ($mysql_db_connect_error); > > $pilt_q = mysql_db_query(DBname,"SELECT pilt,tyyp FROM pildid WHERE > idep='$id'"); > $pilt_k = mysql_fetch_array($pilt_q); > Header("Content-Type: image/pjpeg"); > print($pilt_k["pilt"]); > }?> > /************ end code to show images **************/ > > /************ code to insert images **************/ > if (!empty($pilt) && strlen($pilt)>6) { > $size = GetImageSize ("$pilt"); > $fd = fopen($pilt, "r"); > echo "pildi suurus $size[0], $size[1], id=$id"; > $piltdata = addslashes(fread($fd, filesize($pilt))); > fclose($fd); > mysql_db_query(DBname,"INSERT INTO pildid (tyyp, pilt) VALUES > ('$pilt_type','$piltdata')", $db); > $piltid = mysql_insert_id($db); > } > /************ end code to insert images **************/ > > Any ideas how I could resize the images to 100*75 pixels (from 400*300 pixels)? > Would I do it with "ImageCopyResized"? > > Yours, > Lauri Väin > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#28414) next »