www.webdeveloper.com
Results 1 to 2 of 2

Thread: Upload & resize PNG

  1. #1
    Join Date
    May 2007
    Location
    London, United Kingdom
    Posts
    430

    Upload & resize PNG

    Thanks in advance folks...

    Busy creating a form to upload images. This will create a thumbnail and display the larger image.

    I got the jpeg and gif items to work, but battling with the png. Here is what I have so far...

    PHP Code:
    elseif(($_FILES['photo']['type'] == "image/png") && ($_FILES['photo']['size'] < 51200000)){
    if(
    $_FILES['photo']['error'] == 0){
    if(
    move_uploaded_file($_FILES['photo']['tmp_name'], $photo_direc.$photo_name)){
    $full_photo imagecreatefrompng($photo_direc.$photo_name); 
    list(
    $orig_w$orig_h) = getimagesize($photo_direc.$photo_name);
    $thumb_w 120// NEW THUMB WIDTH
    $thumb_h 100// NEW THUMB HEIGHT
    $create_thumb imagecreatetruecolor($thumb_w$thumb_h); // NEW VAR/CANVAS imageimagecreatetruecolor(WIDTH, HEIGHT)
    $background imagecolorallocate($create_thumb255255255);// fill white due to transparency
    imagefilledrectangle($create_thumb00$thumb_w$thumb_h$background);// fill white due to transparency
    imagecopyresized($create_thumb$full_photo0,0,0,0$thumb_w$thumb_h$orig_w$orig_h);
    imagepng($create_thumb$target_direc.$photo_name50); // CREATE NEW THUMB
    include('success.php'); //file outputs <fieldset> with upload stats
    imagedestroy($full_photo); // ALWAYS REMEMBER TO CLEAN UP
    imagedestroy($create_thumb); // ALWAYS REMEMBER TO CLEAN UP

    I get these two errors:
    Code:
    Warning: imagepng() [function.imagepng]: gd-png: fatal libpng error: zlib failed to initialize compressor -- stream error in C:\xxxxx\xxxxx\xxxxx\image_resize.php on line 114
    
    Warning: imagepng() [function.imagepng]: gd-png error: setjmp returns error condition in C:\xxxxx\xxxxx\xxxxx\image_resize.php on line 114
    Any help would be appreciated :-)

  2. #2
    Join Date
    May 2007
    Location
    London, United Kingdom
    Posts
    430
    Resolved this... I remember now. I read somewhere that the problem is todo with the Quality Of The Image IE: Compression level: from 0 (no compression) to 9.

    Therefore imagepng($create_thumb, $target_direc.$photo_name, 50) needed to change to something like imagepng($create_thumb, $target_direc.$photo_name, 9)

    :-)

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