示例#1
0
function convert_posting($in_name, $out_name, $ws, $hs, $lcd)
{
    global $message;
    $image_info = getimagesize($in_name);
    // get source image width/height
    //
    $sw = $image_info[0];
    $sh = $image_info[1];
    $parts = pathinfo($out_name);
    $file_ext = strtolower($parts['extension']);
    // $file_name = $parts['filename']; // supported from PHP 5.2
    $base_name = $parts['basename'];
    $pos = strrpos($base_name, ".");
    $file_name = substr($base_name, 0, $pos);
    $file_path = $parts['dirname'];
    $in_parts = pathinfo($in_name);
    $in_file_ext = strtolower($in_parts['extension']);
    $message = "[debug]" . $in_file_ext . "." . "(" . $sw . "X" . $sh . ")" . $out_name . "(" . $file_ext . ")";
    $img = false;
    if ($in_file_ext == 'jpg' or $in_file_ext == 'jpeg') {
        $img = imagecreatefromjpeg($in_name);
    } else {
        if ($in_file_ext == 'gif') {
            $img = imagecreatefromgif($in_name);
        } else {
            if ($in_file_ext == 'png') {
                $img = imagecreatefrompng($in_name);
            }
        }
    }
    //$saveFileNameToJpg = $in_parts['dirname'] . "/" . $in_parts['basename'] . ".jpg";
    $saveFileNameToJpg = $out_name . ".jpg";
    $ret = imagejpeg($img, $saveFileNameToJpg, 100);
    $in_name = $saveFileNameToJpg;
    imagedestroy($img);
    // For image quality,
    // resize will be applied from Big image to smalls.
    $cmd = "";
    // WAP Image conversion
    // 320x240
    $dw = $sw;
    $dh = $sh;
    calc_resize($dw, $dh, $ws[0], $hs[0], true);
    $out_file = $file_path . '/exProd_' . $file_name . '_w' . $lcd . '.png';
    $cmd = $cmd . " -resize {$dw}x{$dh} -type Palette -depth 8 {$out_file}";
    /*
    // 40x30 (Thumbnail image for wap)
    $dw = $ws[4];
    $dh = $hs[4];
    $out_file = $file_path . '/' . $file_name . '_w4.png';
    $cmd = $cmd . " -resize '${dw}x${dh}!' -type Palette -depth 8 ${out_file}";
    */
    $cmd_path = "convert";
    if (file_exists("/usr/local/bin/convert")) {
        $cmd_path = "/usr/local/bin/convert";
    } else {
        if (file_exists("/usr/bin/convert")) {
            $cmd_path = "/usr/bin/convert";
        }
    }
    $cmd = "{$cmd_path} {$in_name} " . $cmd;
    $cmd_out = array();
    $ret_val = 0;
    $ret = exec($cmd, $cmd_out, $ret_val);
    chmod($file_path . '/exProd_' . $file_name . '_w' . $lcd . '.png', 0755);
    // test for $ret_val
    return 0;
}
示例#2
0
function convert_waplink($in_name, $out_name, $ws, $hs)
{
    global $message;
    // debug
    // echo '--- THEME resize called : ' . $in_name . ' - ' . $out_name . ' - ' . $ws . 'x' . $hs ;
    $image_info = getimagesize($in_name);
    // get source image width/height
    //
    $sw = $image_info[0];
    $sh = $image_info[1];
    $parts = pathinfo($out_name);
    $file_ext = strtolower($parts['extension']);
    //input 의 확장자
    $input_parts = pathinfo($in_name);
    $input_file_ext = strtolower($input_parts['extension']);
    // $file_name = $parts['filename'];
    $base_name = $parts['basename'];
    $pos = strrpos($base_name, ".");
    $file_name = substr($base_name, 0, $pos);
    $file_path = $parts['dirname'];
    $img = false;
    //gif 이미지를 png 로 변경하기
    // create & load original image
    //$img = imagecreatefromjpeg( $in_name );
    if ($input_file_ext == 'jpg' or $input_file_ext == 'jpeg') {
        $img = imagecreatefromjpeg($in_name);
    } else {
        if ($input_file_ext == 'gif') {
            $img = imagecreatefromgif($in_name);
        } else {
            if ($input_file_ext == 'png') {
                $img = imagecreatefrompng($in_name);
            }
        }
    }
    if ($img == false) {
        $message = "Cannot load image" . "." . $file_ext;
        return -5;
    }
    // wap icon
    $dw = $ws;
    $dh = $hs;
    calc_resize($dw, $dh, $sw, $sh, true);
    imageDestroy($out_img);
    $out_img = imagecreatetruecolor($dw, $dh);
    imagecopyresized($out_img, $img, 0, 0, 0, 0, $dw, $dh, $sw, $sh);
    $ret = imagetruecolortopalette($out_img, true, 255);
    // image, dither, ncolors
    $out_file = $file_path . '/' . $file_name . '.png';
    $ret = imagepng($out_img, $out_file, $file_ext);
    chmod($out_file, 0755);
    if ($ret == false) {
        $message = "Cannot write image";
        return -3;
    }
    imageDestroy($out_img);
    imageDestroy($img);
    return 0;
}
示例#3
0
function convert_posting($in_name, $out_name, $ws, $hs)
{
    $image_info = getimagesize($in_name);
    if (!$image_info) {
        return null;
    }
    // get source image width/height
    //
    $sw = $image_info[0];
    $sh = $image_info[1];
    $parts = pathinfo($out_name);
    $file_ext = strtolower($parts['extension']);
    // $file_name = $parts['filename']; // supported from PHP 5.2
    $base_name = $parts['basename'];
    $pos = strrpos($base_name, ".");
    $file_name = substr($base_name, 0, $pos);
    $file_path = $parts['dirname'];
    // For image quality,
    // resize will be applied from Big image to smalls.
    $cmd = "";
    // WEB Image conversion
    //
    $dw = $sw;
    $dh = $sh;
    //calc_resize( $dw, $dh, $ws[0], $hs[0], true ); // keep original size
    $out_file = $file_path . '/' . $file_name . '.' . $file_ext;
    $cmd = " -resize {$dw}x{$dh} -write {$out_file}";
    // WAP Image conversion
    // 320x240
    $dw = $sw;
    $dh = $sh;
    calc_resize($dw, $dh, $ws[3], $hs[3], true);
    $out_file = $file_path . '/' . $file_name . '_w3.png';
    $opt = "";
    if ($file_ext == 'gif') {
        $opt = "-delete 1-100";
    }
    $cmd .= " -resize {$dw}x{$dh} -type Palette -depth 8 {$opt} -write {$out_file}";
    // 240x320
    $dw = $sw;
    $dh = $sh;
    calc_resize($dw, $dh, $ws[2], $hs[2], true);
    $out_file = $file_path . '/' . $file_name . '_w2.png';
    $cmd .= " -resize {$dw}x{$dh} -type Palette -depth 8 -write {$out_file}";
    // 176x240
    $dw = $sw;
    $dh = $sh;
    calc_resize($dw, $dh, $ws[1], $hs[1], true);
    $out_file = $file_path . '/' . $file_name . '_w1.png';
    $cmd .= " -resize {$dw}x{$dh} -type Palette -depth 8 -write {$out_file}";
    // 40x30 (Thumbnail image for wap)
    $dw = $ws[4];
    $dh = $hs[4];
    $out_file = $file_path . '/' . $file_name . '_w4.png';
    $cmd .= " -resize '{$dw}x{$dh}!' -type Palette -depth 8 {$out_file}";
    $cmd_path = "convert";
    if (file_exists("/usr/local/bin/convert")) {
        $cmd_path = "/usr/local/bin/convert";
    } else {
        if (file_exists("/usr/bin/convert")) {
            $cmd_path = "/usr/bin/convert";
        }
    }
    $cmd = "{$cmd_path} {$in_name} " . $cmd;
    $cmd_out = array();
    $ret_val = 0;
    $ret = exec($cmd, $cmd_out, $ret_val);
    chmod($file_path . '/' . $file_name . '.' . $file_ext, 0755);
    chmod($file_path . '/' . $file_name . '_w1.png', 0755);
    chmod($file_path . '/' . $file_name . '_w2.png', 0755);
    chmod($file_path . '/' . $file_name . '_w3.png', 0755);
    chmod($file_path . '/' . $file_name . '_w4.png', 0755);
    //$image_info = getImageSize($file_path . '/' . $file_name . '.' . $file_ext);
    return $image_info;
}
示例#4
0
function convert_admin($in_name, $out_name, $ws, $hs)
{
    global $message;
    $image_info = getimagesize($in_name);
    // get source image width/height
    //
    $sw = $image_info[0];
    $sh = $image_info[1];
    $parts = pathinfo($out_name);
    $file_ext = strtolower($parts['extension']);
    // $file_name = $parts['filename']; // supported from PHP 5.2
    $base_name = $parts['basename'];
    $pos = strrpos($base_name, ".");
    $file_name = substr($base_name, 0, $pos);
    $file_path = $parts['dirname'];
    // For image quality,
    // resize will be applied from Big image to smalls.
    $cmd = "";
    // WEB Image conversion
    //
    $dw = $sw;
    $dh = $sh;
    calc_resize($dw, $dh, $ws, $hs, false);
    $out_file = $file_path . '/' . $file_name . '.' . $file_ext;
    $cmd = " -resize {$dw}x{$dh} -write {$out_file}";
    // WAP Image conversion
    $dw = $sw;
    $dh = $sh;
    calc_resize($dw, $dh, $ws, $hs, true);
    $out_file = $file_path . '/' . $file_name . '_w3.png';
    $cmd = $cmd . " -resize {$dw}x{$dh} -type Palette -depth 8 -write {$out_file}";
    $cmd_path = "convert";
    if (file_exists("/usr/local/bin/convert")) {
        $cmd_path = "/usr/local/bin/convert";
    } else {
        if (file_exists("/usr/bin/convert")) {
            $cmd_path = "/usr/bin/convert";
        }
    }
    $cmd = "{$cmd_path} {$in_name} " . $cmd;
    $cmd_out = array();
    $ret_val = 0;
    $ret = exec($cmd, $cmd_out, $ret_val);
    chmod($file_path . '/' . $file_name . '.' . $file_ext, 0755);
    chmod($file_path . '/' . $file_name . '_w3.png', 0755);
    // test for $ret_val
    return 0;
}