03-04-07, 01:20 PM
Newbie Coder
Join Date: Aug 2006
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Image Thumbnail Creator
I need a script that will resize images to 120x90 but of course I don't want it distorted. So what needs to happen is, once the image is resized and say its 140x90 the thumbnail will just be cropped to 120x90 get it? Can anybody help? I already have a script that resizes my images into thumbnails of 120x90 but they look awful. I'd rather have them resized and cropped if needed. Any help would be great.
03-04-07, 01:30 PM
Community VIP
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Stating what scripting language you need this to be in would probably help along with any other requirements, such as doing this on the fly or saving the results to a file/database, for what type(s) of images...
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
03-04-07, 01:46 PM
Newbie Coder
Join Date: Aug 2006
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
It needs to be a php class. Here is my current php scripts that I am using. This is the upload_images.php
PHP Code:
<?php
session_start ();
include( "include/config.php" );
include( "include/function.php" );
include( "thumb.class.php" );
chk_member_login ();
isMailVerified ();
#echo "hello" . $_POST[action_upload];
#echo $config['audiodir'];
#echo $config['audiourl'];
if( $_POST [ action_upload ]!= "" )
{
if( $_POST [ field_myvideo_title ]== "" ) $err = "Upload: Please Provide an image title." ;
elseif( $_POST [ field_myvideo_descr ]== "" ) $err = "Upload: Please Provide an image description." ;
elseif( $_POST [ field_myvideo_keywords ]== "" ) $err = "Upload: Please provide tag/s." ;
//elseif(count($_POST[chlist])<1 || count($_POST[chlist])>3) $err="Upload: Please check (1 to 3) channel/s.";
if( $err == "" )
{
STemplate :: assign ( 'secondpage' , "second" );
//$listch=implode("|",$_POST[chlist]);
//STemplate::assign('listch',$listch);
}
}
if( $_POST [ upload_final ]!= "" )
{
#echo "uploading";
if( $_FILES [ 'field_uploadfile' ][ 'tmp_name' ]== "" )
$err = "Please provide the image location." ;
if( $err == "" && $_FILES [ 'field_uploadfile' ][ 'tmp_name' ]!= "" ){
$p = $_FILES [ 'field_uploadfile' ][ 'name' ];
$pos = strrpos ( $p , "." );
$ph = strtolower ( substr ( $p , $pos + 1 , strlen ( $p )- $pos ));
$im_size = $_FILES [ 'field_uploadfile' ][ 'size' ];
if( $ph != "jpg" && $ph != "png" && $ph != "bmp" && $ph != "gif" )
$err = "Invalid Format. The supported formats are png, jpg, bmp and gif" ;
}
if( $err == "" ){
$sql = "insert into images (UID,title,description,keyword,addtime,adddate,vkey,type,filehome) VALUES( $_SESSION [ UID ] ,' $_POST [ field_myvideo_title ] ',' $_POST [ field_myvideo_descr ] ',' $_POST [ field_myvideo_keywords ] ','" . time (). "','" . date ( "Y-m-d" ). "','" . mt_rand (). "',' $_POST [ field_privacy ] ',' $p ')" ;
$conn -> execute ( $sql );
$vid = mysql_insert_id ();
$vdoname = $vid . "." . $ph ;
//VIDEO UPLOADING
if( $config [ 'activexinstall' ]== "no" )
{
if(isset( $_FILES [ 'field_uploadfile' ][ 'tmp_name' ]) && is_uploaded_file ( $_FILES [ 'field_uploadfile' ][ 'tmp_name' ])){
$ff = $config [ 'imagesdir' ]. "/" . $vdoname ;
//echo $ff . "<br>";
if( move_uploaded_file ( $_FILES [ 'field_uploadfile' ][ 'tmp_name' ], $ff ))
{}
else
echo "Error occured while uploading the image" ;
//$mov = new ffmpeg_movie($ff);
//video_to_frame($ff,$vid,&$mov,$listch[0]);
//$duration=$mov->getDuration();
//exec("$config[ffmpeg] -i $config[vdodir]/$vdoname -f flv $config[flvdodir]/".$vid.".flv");
}
}
//END
$key = substr ( md5 ( $vid ), 11 , 20 );
$sql = "update images set
vdoname=' $vdoname ',
vkey=' $key ' WHERE VID= $vid " ;
$conn -> execute ( $sql );
thumb ( $config [ 'AIMG_DIR' ] . "/" . $vdoname , array( 120 , 90 ));
if( mysql_affected_rows ()>= 1 ) header ( "Location: $config [ baseurl ] /upload_success_images.php?viewkey= $key &upload=yes" );exit;
}
}
STemplate :: assign ( 'err' , $err );
STemplate :: assign ( 'msg' , $msg );
STemplate :: assign ( 'head_bottom' , "imageslinks.tpl" );
STemplate :: display ( 'head5.tpl' );
STemplate :: display ( 'err_msg.tpl' );
STemplate :: display ( 'upload_images.tpl' );
STemplate :: display ( 'footer.tpl' );
?>
and this is the script that is currently being used to resize the images
PHP Code:
<?
class thumbnail
{
var $img ;
function thumbnail ( $imgfile )
{
//detect image format
$this -> img [ "format" ]= ereg_replace ( ".*\.(.*)$" , "\\1" , $imgfile );
$this -> img [ "format" ]= strtoupper ( $this -> img [ "format" ]);
if ( $this -> img [ "format" ]== "JPG" || $this -> img [ "format" ]== "JPEG" ) {
//JPEG
$this -> img [ "format" ]= "JPEG" ;
$this -> img [ "src" ] = ImageCreateFromJPEG ( $imgfile );
} elseif ( $this -> img [ "format" ]== "PNG" ) {
//PNG
$this -> img [ "format" ]= "PNG" ;
$this -> img [ "src" ] = ImageCreateFromPNG ( $imgfile );
} elseif ( $this -> img [ "format" ]== "GIF" ) {
//GIF
$this -> img [ "format" ]= "GIF" ;
$this -> img [ "src" ] = ImageCreateFromGIF ( $imgfile );
} elseif ( $this -> img [ "format" ]== "WBMP" ) {
//WBMP
$this -> img [ "format" ]= "WBMP" ;
$this -> img [ "src" ] = ImageCreateFromWBMP ( $imgfile );
} else {
//DEFAULT
echo "Not Supported File" ;
exit();
}
@ $this -> img [ "lebar" ] = imagesx ( $this -> img [ "src" ]);
@ $this -> img [ "tinggi" ] = imagesy ( $this -> img [ "src" ]);
//default quality jpeg
$this -> img [ "quality" ]= 100 ;
}
function size_height ( $size = 100 )
{
//height
$this -> img [ "tinggi_thumb" ]= $size ;
@ $this -> img [ "lebar_thumb" ] = ( $this -> img [ "tinggi_thumb" ]/ $this -> img [ "tinggi" ])* $this -> img [ "lebar" ];
}
function size_width ( $size = 100 )
{
//width
$this -> img [ "lebar_thumb" ]= $size ;
@ $this -> img [ "tinggi_thumb" ] = ( $this -> img [ "lebar_thumb" ]/ $this -> img [ "lebar" ])* $this -> img [ "tinggi" ];
}
function size_auto ( $size = 100 )
{
//size
if ( $this -> img [ "lebar" ]>= $this -> img [ "tinggi" ]) {
$this -> img [ "lebar_thumb" ]= $size ;
@ $this -> img [ "tinggi_thumb" ] = ( $this -> img [ "lebar_thumb" ]/ $this -> img [ "lebar" ])* $this -> img [ "tinggi" ];
} else {
$this -> img [ "tinggi_thumb" ]= $size ;
@ $this -> img [ "lebar_thumb" ] = ( $this -> img [ "tinggi_thumb" ]/ $this -> img [ "tinggi" ])* $this -> img [ "lebar" ];
}
}
function jpeg_quality ( $quality = 100 )
{
//jpeg quality
$this -> img [ "quality" ]= $quality ;
}
function show ()
{
//show thumb
@ Header ( "Content-Type: image/" . $this -> img [ "format" ]);
/* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/
$this -> img [ "des" ] = ImageCreateTrueColor ( $this -> img [ "lebar_thumb" ], $this -> img [ "tinggi_thumb" ]);
@ imagecopyresized ( $this -> img [ "des" ], $this -> img [ "src" ], 0 , 0 , 0 , 0 , $this -> img [ "lebar_thumb" ], $this -> img [ "tinggi_thumb" ], $this -> img [ "lebar" ], $this -> img [ "tinggi" ]);
if ( $this -> img [ "format" ]== "JPG" || $this -> img [ "format" ]== "JPEG" ) {
//JPEG
imageJPEG ( $this -> img [ "des" ], "" , $this -> img [ "quality" ]);
} elseif ( $this -> img [ "format" ]== "PNG" ) {
//PNG
imagePNG ( $this -> img [ "des" ]);
} elseif ( $this -> img [ "format" ]== "GIF" ) {
//GIF
imageGIF ( $this -> img [ "des" ]);
} elseif ( $this -> img [ "format" ]== "WBMP" ) {
//WBMP
imageWBMP ( $this -> img [ "des" ]);
}
}
function save ( $save = "" )
{
//save thumb
if (empty( $save )) $save = strtolower ( "./thumb." . $this -> img [ "format" ]);
/* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/
$this -> img [ "des" ] = ImageCreateTrueColor ( $this -> img [ "lebar_thumb" ], $this -> img [ "tinggi_thumb" ]);
@ imagecopyresized ( $this -> img [ "des" ], $this -> img [ "src" ], 0 , 0 , 0 , 0 , $this -> img [ "lebar_thumb" ], $this -> img [ "tinggi_thumb" ], $this -> img [ "lebar" ], $this -> img [ "tinggi" ]);
if ( $this -> img [ "format" ]== "JPG" || $this -> img [ "format" ]== "JPEG" ) {
//JPEG
imageJPEG ( $this -> img [ "des" ], " $save " , $this -> img [ "quality" ]);
} elseif ( $this -> img [ "format" ]== "PNG" ) {
//PNG
imagePNG ( $this -> img [ "des" ], " $save " );
} elseif ( $this -> img [ "format" ]== "GIF" ) {
//GIF
imageGIF ( $this -> img [ "des" ], " $save " );
} elseif ( $this -> img [ "format" ]== "WBMP" ) {
//WBMP
imageWBMP ( $this -> img [ "des" ], " $save " );
}
}
}
function thumb ( $upload_name , $size = null ){
global $thumb_size ;
if( $size == null ) $size = $thumb_size ? $thumb_size : 200 ;
$thumb =new thumbnail ( $upload_name );
if(! is_array ( $size )) $thumb -> size_auto ( $size );
else{
$thumb -> size_width ( $size [ 0 ]);
$thumb -> size_height ( $size [ 1 ]);
}
$s = explode ( "." , $upload_name );
$thumb_file = $s [ 0 ]. "_thumb." . $s [ 1 ];
//echo $thumb_file;
$thumb -> save ( $thumb_file );
//echo file_exists($thumb_file);
if( file_exists ( $thumb_file )) return $thumb_file ;
else return null ;
}
?>
Hopefully this helps out more. I am looking for a script that resizes my images similar to
www.thatimagesite.com That site has very good thumbnails and they are both resized, cropped, and all 120x90.
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off