www.webdeveloper.com
Results 1 to 8 of 8

Thread: resize tif image

  1. #1
    Join Date
    Nov 2008
    Posts
    61

    resize tif image

    HI!
    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';
    switch($type){
    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($crop){
    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;

    }
    else{
    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);

    switch($type){
    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
    Posts
    61
    any idea?

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,144
    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)); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Jul 2013
    Posts
    1
    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
    Location
    localhost
    Posts
    2,137
    You can simplify the script by using pathinfo() to provide the extension http://www.php.net/manual/en/function.pathinfo.php
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  7. #7
    Join Date
    Apr 2013
    Posts
    26
    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
    Posts
    31
    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,
    Arron

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



Recent Articles