Results 1 to 8 of 8

Thread: resize tif image

  1. #1
    Join Date
    Nov 2008

    resize tif image

    i use the following function to resize image. It is ok with jpg or png but not with tiff..
    Can you help me to fin error please?

    function image_resize($src, $dst, $width, $height, $crop=0){

    if(!list($w, $h) = getimagesize($src)) return "Unsupported picture type!"; //calcola le dimensioni dell'immagine originale

    $type = strtolower(substr(strrchr($src,"."),1));
    if($type == 'jpeg') $type = 'jpg';
    case 'bmp': $img = imagecreatefromwbmp($src); break;
    case 'gif': $img = imagecreatefromgif($src); break;
    case 'jpg': $img = imagecreatefromjpeg($src); break;
    case 'png': $img = imagecreatefrompng($src); break;
    case 'tif': $img = imagecreate($src); break;
    default : return "Unsupported picture type!";

    // resize
    if($w < $width or $h < $height) return "Picture is too small!";
    $ratio = max($width/$w, $height/$h);
    $h = $height / $ratio;
    $x = ($w - $width / $ratio) / 2;
    $w = $width / $ratio;

    if($w < $width and $h < $height) return "Picture is too small!";
    $ratio = min($width/$w, $height/$h);
    $width = $w * $ratio;
    $height = $h * $ratio;
    $x = 0;

    $new = imagecreatetruecolor($width, $height);

    // preserve transparency
    if($type == "gif" or $type == "png"){
    imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127));
    imagealphablending($new, false);
    imagesavealpha($new, true);

    //echo 'new:'.$new.'<br>img:'.$img.'<br>x:'.$x.'<br>widht:'.$width.'<br>height:'.$height.'<br>w:'.$w.'<br>h :'.$h;die;
    imagecopyresampled($new, $img, 0, 0, $x, 0, $width, $height, $w, $h);

    case 'bmp': imagewbmp($new, $dst); break;
    case 'gif': imagegif($new, $dst); break;
    case 'jpg': imagejpeg($new, $dst); break;
    case 'png': imagepng($new, $dst); break;
    return true;

  2. #2
    Join Date
    Nov 2008
    any idea?

  3. #3
    Join Date
    Aug 2004
    I'm not sure that GD supports TIFF images, but I know that imagecreate() expects its arguments to be width and height integers, not a file name. You could try using imagecreatefromstring() and see if it knows what to do with it:
    PHP Code:
    $img imagecreatefromstring(file_get_contents($src)); 
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  4. #4
    Join Date
    Jul 2013
    some program doesn't support tiff image, so there is no way to resize tiff image vb.net under this circumstance. as for the codes, i have no idea what the problem is.

  5. #5
    thank you for the coding

  6. #6
    Join Date
    Mar 2007
    You can simplify the script by using pathinfo() to provide the extension http://www.php.net/manual/en/function.pathinfo.php
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  7. #7
    Join Date
    Apr 2013
    you can try some third party imaging processing dll to do such a deal ,it can make things much easier. I use an imaging sdk driver found on the internet . Install it and it becomes a selectable processing option.Then you can resize your image in any program at all, including Adobe Acrobat .zoom in or zoom out on your own will. Just open the images, select resize ,and follow the setps given in the sdk, the task will be finished in several seconds. if you haven't found a good choice , you can have a try. best wishes.

  8. #8
    Join Date
    Apr 2013
    Thanks for your nice info. I agree with you that using a professional Tiff Processor to resize its file can make all the progress much more convenient than before. I will try your sharing later.

    Best regards,

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center