alapimba Posted November 15, 2006 Share Posted November 15, 2006 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: 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? Quote Link to comment https://forums.phpfreaks.com/topic/27328-how-to-convert-tiff-to-jpg-with-php/ Share on other sites More sharing options...
zq29 Posted November 15, 2006 Share Posted November 15, 2006 As far as I'm aware, the GDLib doesn't support conversions from/to TIFF formats. You'll need some third party tool installed on the server, such as ImageMagick. Converting with ImageMagick is simple: <?php exec('convert path/to/original/image.tiff path/to/new/image.jpg'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/27328-how-to-convert-tiff-to-jpg-with-php/#findComment-124929 Share on other sites More sharing options...
falakniazi Posted October 22, 2011 Share Posted October 22, 2011 Following code allows you to convert a multi-page TIFF file to JPG thumbnail. This conversion is usually required in those situations where you have to allow users to view a Fax document on a webpage. Since web browsers usually doesn’t support TIFF extensions. So you have to convert these documents to either JPG or PDF. Following code works for both situations. you just need to change jgp with pdf. Following code is taken from sourcecodemania.com <?php try { // Saving every page of a TIFF separately as a JPG thumbnail $images = new Imagick("testing.tif"); foreach($images as $i=>$image) { // Providing 0 forces thumbnail Image to maintain aspect ratio $image->thumbnailImage(768,0); $image->writeImage("page".$i.".jpg"); echo "<img src='page$i.jpg' alt='images' ></img>"; } $images->clear(); } catch(Exception $e) { echo $e->getMessage(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/27328-how-to-convert-tiff-to-jpg-with-php/#findComment-1281379 Share on other sites More sharing options...
hiimage Posted July 8, 2013 Share Posted July 8, 2013 the souce codes i know about convert tiff to jpg is limited in this programing language. i'd love to know more with php. thank you for all of your help. Quote Link to comment https://forums.phpfreaks.com/topic/27328-how-to-convert-tiff-to-jpg-with-php/#findComment-1439866 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.