Jump to content
php.lv forumi

Recommended Posts

Posted

Tamm man vajadzētu apmēram ideju, kā notiek bildes thumbnail veidošana, ja bilde NAV uz servera bet ir no URL

 

saņemu

ieseivoju cache mapē

resize

echo

 

google nepalīdzēja :/

Posted

tamm pašlaik esmu izpipējis šitik tālu:

 

function curl($url,$name)
{
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec ($ch);
curl_close ($ch);

$fp = fopen("cache/",'w');

//seit laikam ar rawdata vajadzētu veikt `manipulācijas` [ pārveidot lielumu utt. ]

fwrite($fp, $rawdata); 
fclose($fp);
}

Posted

kaut kas laikam nestrādā kā vajag.

 

funkcijas.php

function curl($url)
{
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec ($ch);
curl_close ($ch);

$fp = fopen("cache/",'w');

$im = imagecreatefromstring($rawdata);
if ($im !== false) {
   header('Content-Type: image/png');
   imagepng($im);
   imagedestroy($im);
}

fwrite($fp, $im); 
fclose($fp);
}

 

atteelo.php

<div class="panel">
<?php 
$screen = get_post_meta($post->ID, 'screen', $single = true);
curl($screen);
$name = basename($screen);
}
?>
<img src="cache/<?php echo $name ?>" class="reflect ropacity30 rheight30" width="200" height="100" />
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
</div>

Posted

tā man tagad izdevās laikam.

 

$screen = get_post_meta($post->ID, 'screen', $single = true);
$dest = './images/'.basename($screen);
if(!file_exists($dest))
{
curl($screen,$dest);
crop($dest,$dest,200,100);
}

 

un abas f-jas

function crop($src, $dst, $width, $height){
       if(!$src = imagecreatefromstring(file_get_contents($src))) return false;
       $srcw = imagesx($src);
       $srch = imagesy($src);
       $tmp = imagecreatetruecolor($width, $height); // uztaisam attēlu
       imagefilledrectangle($tmp, 0, 0, $width, $height, imagecolorallocate($tmp, 255, 255, 255)); // balts fons
       // sākās visa rēķināšanas daļa
       if($srcw <= $width && ($srch <= $height || $height == 0)){
               $nw = $srcw;
               $nh = $srch;
       }else{
               $ratio = $srcw/$srch;
               if($height > 0 && $width/$height > $ratio){
                       $nw = $height*$ratio;
                       $nh = $height;
               }else{
                       $nw = $width;
                       $nh = $width/$ratio;
               }
       }
       imagecopyresampled($tmp, $src, (($width/2)-($nw/2)), (($height/2)-($nh/2)), 0, 0, $nw, $nh, $srcw, $srch); // resize
       if(!imagejpeg($tmp, $dst, 100)) return false;
       imagedestroy($tmp);
       return true;
}

function curl($url, $img) 
   { 
$ch = curl_init ($url);
   curl_setopt($ch, CURLOPT_HEADER, 0);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
   $rawdata=curl_exec($ch);
   curl_close ($ch);
   $fp = fopen($img,'x');
   fwrite($fp, $rawdata);
   fclose($fp);
   }

 

tagad viņš uztaisa 200x100px, sānos liekot baltu krāsu.

f-ju tepeat atradu kaut kur.

 

ir iespējams savādāks resize skripts, kad samazina uz noteiktiem izmēriem, bet bilde neizskatās tik saspiesta kā izmantojot

<img src="" width="X" height="X" /> ?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...