You are here: Trying to make a thumbnail but fails « PHP Programming Language « IT news, forums, messages
Trying to make a thumbnail but fails

Posted by pek on 12/18/57 11:51

I created a file name image.php which contains only the following code:

<?php
function createThumbnail($picture,$thumb,$new_w,$new_h) {
$extension=substr($picture,strrpos($picture,".")+1);
switch (strtolower($extension)) {
case "jpg":
case "jpeg":
$src_img=imagecreatefromjpeg($picture);
break;
case "png":
$src_img=imagecreatefrompng($picture);
break;
case "gif":
$src_img=imagecreatefromgif($picture);
break;
case "bmp":
$src_img=imagecreatefromwbmp($picture);
break;
}

$old_x=imagesx($src_img);
$old_y=imagesy($src_img);

if ($old_x > $old_y) {
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}elseif ($old_x < $old_y) {
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}else{
$thumb_w=$new_w;
$thumb_h=$new_h;
}

$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);


switch (strtolower($extension)) {
case "jpg":
case "jpeg":
imagejpeg($dst_img,$thumb);
break;
case "png":
imagepng($dst_img,$thumb);
break;
case "gif":
imagegif($dst_img,$thumb);
break;
case "bmp":
imagewbmp($dst_img,$thumb);
break;
}

imagedestroy($dst_img);
imagedestroy($src_img);
}
?>

This function successfully creates a thumbnail. The problem is that I
include it in another page (with include_once, just if it matters)
which creates a thumbnail, makes some db updates and then redirects to
another page. When trying to redirect with header("Location:
index.php"); it echos that header has already been sent from image.php.
The problem appears immediatly on include (I deleted the code that
calls the function to test it).
I think it is because I am using imagejpg(); function which outputs to
the browser but I don't know how to change this.
Thanks in advance

-pek

P.S. I know my coding skills are awful, so if there is anyone
suggesting to change the way I create the thumbnail please do.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация