이미지 리사이즈 소스입니다. 정보
이미지 리사이즈 소스입니다.본문
제가 다른 프로그램 만들때 이미지 리라이즈용으로 쓰는거여요.
(물론 캘러리 게시판 만들때 응용하심돼요.)
- 공개형 소스이고, 출처는 저도 모릅니다.
- 사용법은 하단에 올릴게요.. 처음 적용할때는 어렵습니다.
특징: 이미지 사이즈를.. 원본을 최대한 파손하지 않는 형식입니다.
특히 디비와 연동시에 큰 효과를 봅니다.
해당파일의 이름을 아무거로 하세요( 예- resite_image.php )
====================================================================
( 예- resite_image.php )
<?php
$image = $_REQUEST['image'];
$max_width = $_REQUEST['max_width'];
$max_height = $_REQUEST['max_height'];
if (!$max_width)
$max_width = 80;
if (!$max_height)
$max_height = 60;
$size = GetImageSize($image);
$width = $size[0];
$height = $size[1];
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if ( ($width <= $max_width) && ($height <= $max_height) ) {
$tn_width = $width;
$tn_height = $height;
}
else if (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
$src = ImageCreateFromJpeg($image);
$dst = ImageCreate($tn_width,$tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0,
$tn_width,$tn_height,$width,$height);
header('Content-type: image/jpeg');
ImageJpeg($dst, null, -1);
ImageDestroy($src);
ImageDestroy($dst);
?>
(물론 캘러리 게시판 만들때 응용하심돼요.)
- 공개형 소스이고, 출처는 저도 모릅니다.
- 사용법은 하단에 올릴게요.. 처음 적용할때는 어렵습니다.
특징: 이미지 사이즈를.. 원본을 최대한 파손하지 않는 형식입니다.
특히 디비와 연동시에 큰 효과를 봅니다.
해당파일의 이름을 아무거로 하세요( 예- resite_image.php )
====================================================================
( 예- resite_image.php )
<?php
$image = $_REQUEST['image'];
$max_width = $_REQUEST['max_width'];
$max_height = $_REQUEST['max_height'];
if (!$max_width)
$max_width = 80;
if (!$max_height)
$max_height = 60;
$size = GetImageSize($image);
$width = $size[0];
$height = $size[1];
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if ( ($width <= $max_width) && ($height <= $max_height) ) {
$tn_width = $width;
$tn_height = $height;
}
else if (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
$src = ImageCreateFromJpeg($image);
$dst = ImageCreate($tn_width,$tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0,
$tn_width,$tn_height,$width,$height);
header('Content-type: image/jpeg');
ImageJpeg($dst, null, -1);
ImageDestroy($src);
ImageDestroy($dst);
?>
추천
0
0
댓글 9개
너무 감사합니다.
큰 도움이 되겠어요.
큰 도움이 되겠어요.
처음 저도 적용하기 힘들었는데요... 여러가지 방법으로 해보세요..
잘 되더라고요. ^^ 캘러리 스킨 만들때 무지 좋구요.
잘 되더라고요. ^^ 캘러리 스킨 만들때 무지 좋구요.
구누보드같은 경우...... 아래처럼 적용 하심 됩니다.( 이미지 보여줄곳)
<?
// 이미지
echo "<a href='{$list[$i][href]}'>";
$image = urlencode($list[$i][file][0][file]);
if (preg_match("/\.(gif|jpg|png)$/i", $image)) {
echo '<img src="../m_shop/image_size.php?image=';
echo "$g4[path]/data/file/$bo_table/$image";
echo '&max_width=120&max_height=200" border=0 align = left>';
echo "</a>";
}
else if (!file_exists($list[$i][file_image0])){
echo "no image file";
}
?>
<?
// 이미지
echo "<a href='{$list[$i][href]}'>";
$image = urlencode($list[$i][file][0][file]);
if (preg_match("/\.(gif|jpg|png)$/i", $image)) {
echo '<img src="../m_shop/image_size.php?image=';
echo "$g4[path]/data/file/$bo_table/$image";
echo '&max_width=120&max_height=200" border=0 align = left>';
echo "</a>";
}
else if (!file_exists($list[$i][file_image0])){
echo "no image file";
}
?>
> ImageJpeg($dst, null, -1);
ImageJpeg에서 quality 부분에 -1은 무슨뜻인가요?
quality부분은 0~100 사이의 값이 와야하는것 아닌가요?
그리고 이미지의 용량의 줄이는것은 위의 quality를 조정하셔야 할것같습니다.
ImageJpeg에서 quality 부분에 -1은 무슨뜻인가요?
quality부분은 0~100 사이의 값이 와야하는것 아닌가요?
그리고 이미지의 용량의 줄이는것은 위의 quality를 조정하셔야 할것같습니다.
제가 그쪽으로는 꽝이라... root 님 말이 맞네요.. 0 ~ 100
출처: http://au3.php.net/manual/en/function.imagejpeg.php
imagejpeg ( resource image [, string filename [, int quality]] )
버전
JPEG support is only available if PHP was compiled against GD-1.8 or later.
[, int quality]]
quality is optional, and ranges from 0 (worst quality, smaller file) to 100
(best quality, biggest file). The default is the default IJG quality value (about 75).
==>> 0 ~ 100 까지 option
==================================================================
근데 왜 -1 로 해두 잘돼지.. 컨닝한거라 정확한 답변을 못하겠네요..흑흑 ㅡ,ㅡㅡ;;;
출처: http://au3.php.net/manual/en/function.imagejpeg.php
http://ffmpeg-php.sourceforge.net/
여기를 따라가보니..더 좋은것들이 있네요.
출처: http://au3.php.net/manual/en/function.imagejpeg.php
imagejpeg ( resource image [, string filename [, int quality]] )
버전
JPEG support is only available if PHP was compiled against GD-1.8 or later.
[, int quality]]
quality is optional, and ranges from 0 (worst quality, smaller file) to 100
(best quality, biggest file). The default is the default IJG quality value (about 75).
==>> 0 ~ 100 까지 option
==================================================================
근데 왜 -1 로 해두 잘돼지.. 컨닝한거라 정확한 답변을 못하겠네요..흑흑 ㅡ,ㅡㅡ;;;
출처: http://au3.php.net/manual/en/function.imagejpeg.php
http://ffmpeg-php.sourceforge.net/
여기를 따라가보니..더 좋은것들이 있네요.
유용할거 같아요.. 시간날때 써먹게 여기에 올려놓을게요..
----------------------------------------------------
function create_thumbnail( $source_file, $destination_file, $max_dimension)
{
list($img_width,$img_height) = getimagesize($source_file); // Get the original dimentions
$aspect_ratio = $img_width / $img_height;
if ( ($img_width > $max_dimension) || ($img_height > $max_dimension) ) // If either dimension is too big...
{
if ( $img_width > $img_height ) // For wide images...
{
$new_width = $max_dimension;
$new_height = $new_width / $aspect_ratio;
}
elseif ( $img_width < $img_height ) // For tall images...
{
$new_height = $max_dimension;
$new_width = $new_height * $aspect_ratio;
}
elseif ( $img_width == $img_height ) // For square images...
{
$new_width = $max_dimension;
$new_height = $max_dimension;
}
else { echo "Error reading image size."; return FALSE; }
}
else { $new_width = $img_width; $new_height = $img_height; } // If it's already smaller, don't change the size.
// Make sure these are integers.
$new_width = intval($new_width);
$new_height = intval($new_height);
$thumbnail = imagecreatetruecolor($new_width,$new_height); // Creates a new image in memory.
// The following block retrieves the source file. It assumes the filename extensions match the file's format.
if ( strpos($source_file,".gif") ) { $img_source = imagecreatefromgif($source_file); }
if ( (strpos($source_file,".jpg")) || (strpos($source_file,".jpeg")) )
{ $img_source = imagecreatefromjpeg($source_file); }
if ( strpos($source_file,".bmp") ) { $img_source = imagecreatefromwbmp($source_file); }
if ( strpos($source_file,".png") ) { $img_source = imagecreatefrompng($source_file); }
// Here we resample and create the new jpeg.
imagecopyresampled($thumbnail, $img_source, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height);
imagejpeg( $thumbnail, $destination_file, 100 );
// Finally, we destroy the two images in memory.
imagedestroy($img_source);
imagedestroy($thumbnail);
}
----------------------------------------------------
function create_thumbnail( $source_file, $destination_file, $max_dimension)
{
list($img_width,$img_height) = getimagesize($source_file); // Get the original dimentions
$aspect_ratio = $img_width / $img_height;
if ( ($img_width > $max_dimension) || ($img_height > $max_dimension) ) // If either dimension is too big...
{
if ( $img_width > $img_height ) // For wide images...
{
$new_width = $max_dimension;
$new_height = $new_width / $aspect_ratio;
}
elseif ( $img_width < $img_height ) // For tall images...
{
$new_height = $max_dimension;
$new_width = $new_height * $aspect_ratio;
}
elseif ( $img_width == $img_height ) // For square images...
{
$new_width = $max_dimension;
$new_height = $max_dimension;
}
else { echo "Error reading image size."; return FALSE; }
}
else { $new_width = $img_width; $new_height = $img_height; } // If it's already smaller, don't change the size.
// Make sure these are integers.
$new_width = intval($new_width);
$new_height = intval($new_height);
$thumbnail = imagecreatetruecolor($new_width,$new_height); // Creates a new image in memory.
// The following block retrieves the source file. It assumes the filename extensions match the file's format.
if ( strpos($source_file,".gif") ) { $img_source = imagecreatefromgif($source_file); }
if ( (strpos($source_file,".jpg")) || (strpos($source_file,".jpeg")) )
{ $img_source = imagecreatefromjpeg($source_file); }
if ( strpos($source_file,".bmp") ) { $img_source = imagecreatefromwbmp($source_file); }
if ( strpos($source_file,".png") ) { $img_source = imagecreatefrompng($source_file); }
// Here we resample and create the new jpeg.
imagecopyresampled($thumbnail, $img_source, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height);
imagejpeg( $thumbnail, $destination_file, 100 );
// Finally, we destroy the two images in memory.
imagedestroy($img_source);
imagedestroy($thumbnail);
}
자신도 도움받았다고...써보라는데요.... 도움이 됬으면 한다는데..
(끙..해석 맞나 몰겠냉 - ^^ 제가 적용해볼라고 코멘트에 남겨요.. free 쓰라내요.)
Here's another on-the-fly thumbnail creation script.
When I scripted the pictuerviewer on my page, I had all the pictures only in full size and qualit, because I wanted the posibility für visitors to download the pictures.
But as Imagesizes of more than 4 MP are to large for websites, I created thumbnails and the smaller pictures on the fly. But I found out, that the Script needed too much RAM, especially in the thumbnail overview, when I had more then 50 thumbnails to create on the fly at the same time.
So I modified my image creator and my viewer to let them store images, that are created. So only the first visitor has to wait (which is usually me for controlling the uploads und updates), all other visitors get the stored images, which is much faster.
Create different folders. I have a main folder called 'imagesdb' and the tree subfolders full (Full quality images), show (images for the picture viewer) and thumb (for thumbnails in overview).
Store the script for example as image.php and link it like that:
================== image.php ======================
<?PHP
$image_name = "foo.jpg";
$style = "show";
// I've taken the foldernames. It's easier. For the
//thumbnails replace "show" with "thumb".
$image_name = "imagesdb/$style/$image_name";
if(!file_exists($image_name))
$image_name = "image.php?image_name=$image_name&style=$style";
// only if file doesn't exist call the on-the-fly creating file
?>
Now the main script, stored in the file image.php:
<?PHP
$image_name = $_GET['image_name'];
$style = $_GET['style'];
// Now set the maximum sizes to the different styles.
// You may set additional styles, but remember to
// create the according subfolders.
switch($style) {
case "show":
$max_size = 800;
break;
case "thumb":
$max_size = 125;
}
$dest_file = "imagesdb/$style/$image_name";
// set output file
$image_file = "imagesdb/full/$image_name";
// set source file
$size = getimagesize($image_file);
// get original size
if($size[0] > $size[1]) {
$divisor = $size[0] / $max_size;
}
else {
$divisor = $size[1] / $max_size;
}
// to get allways pictures of the same size, which ist
// mostly wanted in imageviewers, look what ist larger:
// width or height
$new_width = $size[0] / $divisor;
$new_height = $size[1] / $divisor;
// set new sizes
settype($new_width, 'integer');
settype($new_height, 'integer');
// sizes should be integers
$image_big = imagecreatefromjpeg($image_file);
// load original image
$image_small = imagecreatetruecolor($new_width, $new_height);
// create new image
imagecopyresampled($image_small, $image_big, 0,0, 0,0, $new_width,$new_height, $size[0],$size[1]);
// imageresampled whill result in a much higher quality
// than imageresized
imagedestroy($image_big);
// the original data are no longer used
header("Content-type: image/jpeg");
if($style=="show" || $style=="thumb") {
if(!file_exists($dest_file))
imagejpeg($image_small, $dest_file, 100);
}
// if you have set additional sizese put them in the
// if-arguments, too.
// if someone calls the image.php directly in the
// browser with imagenames allready existing, they
// won't be overwritten
imagejpeg($image_small, '', 100);
imagedestroy($image_small);
// finally send image to browser and destroy no longer
// needed data.
?>
=====================================================================
As this website helped me for several times in the past and for creating this script, I hope I can help others with this script saving the time for developing a much more performant solution than an allways-on-the-fly-creating script.
(끙..해석 맞나 몰겠냉 - ^^ 제가 적용해볼라고 코멘트에 남겨요.. free 쓰라내요.)
Here's another on-the-fly thumbnail creation script.
When I scripted the pictuerviewer on my page, I had all the pictures only in full size and qualit, because I wanted the posibility für visitors to download the pictures.
But as Imagesizes of more than 4 MP are to large for websites, I created thumbnails and the smaller pictures on the fly. But I found out, that the Script needed too much RAM, especially in the thumbnail overview, when I had more then 50 thumbnails to create on the fly at the same time.
So I modified my image creator and my viewer to let them store images, that are created. So only the first visitor has to wait (which is usually me for controlling the uploads und updates), all other visitors get the stored images, which is much faster.
Create different folders. I have a main folder called 'imagesdb' and the tree subfolders full (Full quality images), show (images for the picture viewer) and thumb (for thumbnails in overview).
Store the script for example as image.php and link it like that:
================== image.php ======================
<?PHP
$image_name = "foo.jpg";
$style = "show";
// I've taken the foldernames. It's easier. For the
//thumbnails replace "show" with "thumb".
$image_name = "imagesdb/$style/$image_name";
if(!file_exists($image_name))
$image_name = "image.php?image_name=$image_name&style=$style";
// only if file doesn't exist call the on-the-fly creating file
?>
Now the main script, stored in the file image.php:
<?PHP
$image_name = $_GET['image_name'];
$style = $_GET['style'];
// Now set the maximum sizes to the different styles.
// You may set additional styles, but remember to
// create the according subfolders.
switch($style) {
case "show":
$max_size = 800;
break;
case "thumb":
$max_size = 125;
}
$dest_file = "imagesdb/$style/$image_name";
// set output file
$image_file = "imagesdb/full/$image_name";
// set source file
$size = getimagesize($image_file);
// get original size
if($size[0] > $size[1]) {
$divisor = $size[0] / $max_size;
}
else {
$divisor = $size[1] / $max_size;
}
// to get allways pictures of the same size, which ist
// mostly wanted in imageviewers, look what ist larger:
// width or height
$new_width = $size[0] / $divisor;
$new_height = $size[1] / $divisor;
// set new sizes
settype($new_width, 'integer');
settype($new_height, 'integer');
// sizes should be integers
$image_big = imagecreatefromjpeg($image_file);
// load original image
$image_small = imagecreatetruecolor($new_width, $new_height);
// create new image
imagecopyresampled($image_small, $image_big, 0,0, 0,0, $new_width,$new_height, $size[0],$size[1]);
// imageresampled whill result in a much higher quality
// than imageresized
imagedestroy($image_big);
// the original data are no longer used
header("Content-type: image/jpeg");
if($style=="show" || $style=="thumb") {
if(!file_exists($dest_file))
imagejpeg($image_small, $dest_file, 100);
}
// if you have set additional sizese put them in the
// if-arguments, too.
// if someone calls the image.php directly in the
// browser with imagenames allready existing, they
// won't be overwritten
imagejpeg($image_small, '', 100);
imagedestroy($image_small);
// finally send image to browser and destroy no longer
// needed data.
?>
=====================================================================
As this website helped me for several times in the past and for creating this script, I hope I can help others with this script saving the time for developing a much more performant solution than an allways-on-the-fly-creating script.
사용해 볼려고 해도.........
그렇니까 완전한 소스는 어떻게되는가요?
손 안데고 코풀려면요.
있는 것 적용하는데만도 몇 일씩 킁킁 앓는데..
정리를 해주시면..........
이미지 보여줄 곳에 넣을 소스는 일반적인 스킨 파일에서 list_skin.php에서 이미지 출력부분에 넣으면 되는거죠???
그렇니까 완전한 소스는 어떻게되는가요?
손 안데고 코풀려면요.
있는 것 적용하는데만도 몇 일씩 킁킁 앓는데..
정리를 해주시면..........
이미지 보여줄 곳에 넣을 소스는 일반적인 스킨 파일에서 list_skin.php에서 이미지 출력부분에 넣으면 되는거죠???
손 안데고 코 풀수는 없고요..
실재 적용된 예는 스킨란에 올렸습니다.. 참고 하시면 될듯 합니다.
http://sir.co.kr/bbs/tb.php/g4_skin/43608
* 소스에 또다른 ..보이지 않는 소스도 참고할만해요.. ^^
실재 적용된 예는 스킨란에 올렸습니다.. 참고 하시면 될듯 합니다.
http://sir.co.kr/bbs/tb.php/g4_skin/43608
* 소스에 또다른 ..보이지 않는 소스도 참고할만해요.. ^^