2012-03-09 4 views

答えて

2

まず、別のサーバーからイメージを取得する必要があります。そのためにはfile_get_contents()を使用できます。

画像のサイズを変更するにはコードが必要です。 curl and resize remote image

を使用すると、オリジナルのに対して、それをダウンサイズを変更したい場合は、現在のサイズを取得するためにgetimagesizefromstring()を使用し、その後、単に:あなたは、文字列内の画像コンテンツではなく、ローカルファイルを持っているので、あなたはここにしようとimagecreatefromstring()を使用することができます選択したパーセンテージに基づいて新しいサイズを計算します。

$content = file_get_contents('http://site.com/image.jpg'); 

$originalSize = getimagesizefromstring($content); 

$originalWidth = $originalSize[0]; 
$originalheight = $originalSize[1]; 

$newSize = 0.6; // 60% of the original size 

$newWidth = $originalWidth * $newSize; 
$newHeight = $originalHeight * $newSize; 

// now you know what the resized width and height should be, you can go ahead and do the actual resizing 
+0

- しかし、私は...それはSHLD元の画像に相対的で、私の端からサイズを修正したいいけない..私はそれを含めるように答えを編集した – Hacker

+0

@Hacker。 – MrCode

関連する問題