# How to convert tiff to jpg with php?

**URL:** <https://forum.kirupa.com/t/how-to-convert-tiff-to-jpg-with-php/207182>\
**Category:** Uncategorized\
**Created:** [November 15, 2006, 11:15am UTC](https://forum.kirupa.com/t/how-to-convert-tiff-to-jpg-with-php/207182 "2006-11-15T11:15:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![alapimba](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@alapimba](https://forum.kirupa.com/u/alapimba)\
**Post date:** [November 15, 2006, 11:15am UTC](https://forum.kirupa.com/t/how-to-convert-tiff-to-jpg-with-php/207182/1 "2006-11-15T11:15:21Z")

</div>

Hello  
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 😃

here is my code that it’s working fine:

```php
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);
}else{
$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;
imagedestroy($destimg);
$fh = fopen($prod_img, 'w') or die("can't open file");
fclose($fh);
unlink($prod_img);
$dir = $uploadfile;
}
}

```

anyone can help me?
