How to convert tiff to jpg with php?

I’m building a backend to allow a client to upload images to his site.
But my client has a lot of images in tiff format so i’d like to be able to convert tiff to jpg and only after that upload the image.
i’m using the command move_uploaded_file to upload the original image and then i’m resizing the image and creating a new one and delete the original. now i want to add to my script a way to convert the original tiff to jpeg, resize save and delete the original :smiley:

here is my code that it’s working fine:

if ($_FILES['foto']['name'] == "") {
    $dir = "images/spacer.gif";
} else { 
$size = 124; // the thumbnail height
$filedir = 'img/ambientes/'; // the directory for the original image
$thumbdir = 'img/ambientes/'; // the directory for the thumbnail image
$prefix = 'small_'; // the prefix to be added to the original name
$maxfile = '200000';
$mode = '0666';
$userfile_name = $_FILES['foto']['name'];
$userfile_tmp = $_FILES['foto']['tmp_name'];
$userfile_size = $_FILES['foto']['size'];
$userfile_type = $_FILES['foto']['type'];
if (isset($_FILES['foto']['name'])) 
$prod_img = $filedir.$userfile_name;
$prod_img_thumb = $thumbdir.$prefix.$userfile_name;
move_uploaded_file($userfile_tmp, $prod_img);
chmod ($prod_img, octdec($mode));
$sizes = getimagesize($prod_img);
$aspect_ratio = $sizes[0]/$sizes[1]; 
if ($sizes[0] <= $size)
$new_width = $size;
$new_height = abs($new_width*$aspect_ratio);
$new_width = $size;
$new_height = abs($new_width/$aspect_ratio);
$destimg=ImageCreateTrueColor($new_width,$new_height) or die('Problem In Creating image');
$srcimg=ImageCreateFromJPEG($prod_img) or die('Problem In opening Source Image');
ImageCopyResampled($destimg, $srcimg, 0, 0, 0, 0, $new_width, $new_height, $sizes[0], $sizes[1]) or die('Problem In resampling');
ImageJPEG($destimg,$prod_img_thumb,90) or die('Problem In saving');
$uploadfile = $prod_img_thumb;
$fh = fopen($prod_img, 'w') or die("can't open file");
$dir = $uploadfile;

anyone can help me?