Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Problem sa prikazivanjem slika

[es] :: PHP :: Problem sa prikazivanjem slika

[ Pregleda: 794 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

KumRusvelt
Božidar Mirković
Beograd, Srbija

Član broj: 248295
Poruke: 18
95.180.124.*



Profil

icon Problem sa prikazivanjem slika03.03.2016. u 12:05 - pre 99 meseci
Pozdrav svima!
Imam problem sa prikazivenjem slika u izradi sajta, naime kada želim da prikažem sajt na bilo kom browseru slike se neprikazuju, kada pozovem Ctrl+u browser javlja sa crvenim oznakama gde je greška, a kada pritisnem na link slike prikazuje mi skriptu u php-u resize koju u jednom delu kao da nerazume šat sma hteo uraditi, hvala unapred na sugestiji.

Da ima opcije slanje slika poslao bih vam slike sa browsera gde mi nagoveštava greške, ovako mi preostaje da vam prosledim skriptu resize.php

Code:

<?
if(!isset($_GET["i"]))$img = "nema";
else $img = $_GET["i"];
if(!isset($_GET["c"]))$crop = 'f';
else $crop = $_GET["c"];
if(!isset($_GET["w"]))$gwidth = -1;
else $gwidth = $_GET["w"];
if(!isset($_GET["h"]))$gheight = -1;
else $gheight = $_GET["h"];

$imagepath = "";
//$img = "glavna_16113.jpg";
//$img = "468.gif";
//$img = "faintinggoats.gif";

//$image = imagecreatefromjpeg($imagepath.$img);

if(!file_exists($imagepath.$img)){ die();}
$img_info = getimagesize($imagepath.$img);
$width = $img_info[0];
$height = $img_info[1];
$mime = $img_info['mime'];
if(substr($mime, 0, 6) != 'image/'){ die();}

define('MEMORY_TO_ALLOCATE',    '100M');

if($mime == 'image/gif'){
    $image = imagecreatefromgif($imagepath.$img);
}elseif(($mime == 'image/png')||($mime == 'image/x-png')){
    $image = imagecreatefrompng($imagepath.$img);
}elseif(($mime == 'image/jpeg')||($mime == 'image/pjpeg')){
    $image = imagecreatefromjpeg($imagepath.$img);
}else{ die();}

if(($gwidth != -1)&&($gheight != -1)){
    $imgratio = $width/$height;
    $newwidth = $gwidth;
    $newheight = $gheight;
    $nh = $newwidth/$imgratio;
    if(($nh > $newheight)&&($crop == 'a')){
        $imgratio = $newwidth/$newheight;
        $height = $width/$imgratio;
    }else{if(($height < $newheight)&&($crop == 'a')){$newheight = $height;$crop = 't';}}
}elseif(($gwidth == -1)&&($gheight == -1)){
    $newwidth = $width;
    $newheight = $height;
}else{
    if($gwidth != -1){
        $imgratio = $width/$height;
        $ImgSize = $gwidth;
        $newwidth = $ImgSize;
        $newheight = $ImgSize/$imgratio;
    }
    if($gheight != -1){
        $imgratio = $height/$width;
        $ImgSize = $gheight;
        $newwidth = $ImgSize/$imgratio;
        $newheight = $ImgSize;
    }
}
$resized_img = imagecreatetruecolor($newwidth, $newheight);
if(in_array($mime, array('image/jpg', 'image/gif', 'image/png', 'image/x-png'))){
    // If this is a GIF or a PNG, we need to set up transparency
    if(function_exists('imagesavealpha')){imagealphablending($resized_img, false);}
    if(function_exists('imagesavealpha')){imagesavealpha($resized_img, true);}
}

if($crop == 't'){imagecopy($resized_img, $image, 0, 0, 0, 0, $newwidth, $newheight);}
else{imagecopyresampled($resized_img, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);}


imagedestroy($image);
if(function_exists('imageconvolution')){
    $sharpness    = findSharp($width, $newwidth);
    $sharpenMatrix    = array(
        array(-1, -2, -1),
        array(-2, $sharpness + 12, -2),
        array(-1, -2, -1)
    );
    $divisor        = $sharpness;
    $offset            = 0;
    imageconvolution($resized_img, $sharpenMatrix, $divisor, $offset);
}

ob_start();
if(($mime == 'image/jpeg')||($mime == 'image/pjpeg')){
    imagejpeg($resized_img);
}elseif($mime == 'image/gif'){
    imagegif($resized_img);
}elseif(($mime == 'image/png')||($mime == 'image/x-png')){
    imagepng($resized_img);
}
$data = ob_get_contents();
ob_end_clean();
imagedestroy($resized_img);

header('Content-Type: '.$mime);
header('Content-Length: '.strlen($data));
echo $data;


function findSharp($orig, $final){ // function from Ryan Rud (http://adryrun.com)
    $final    = $final * (750.0 / $orig);
    $a        = 52;
    $b        = -0.27810650887573124;
    $c        = .00047337278106508946;
    $result = $a + $b * $final + $c * $final * $final;
    return max(round($result), 0);
} // findSharp()

?>


i prikaz browsera

Code:
<td>
<img src="showImage.php?i=images/doimage.jpg&w=100&h=60">
</td>
<td width=230>
&nbsp;&nbsp;&nbsp; <a href="#" class="moar">Link</a><br/>&nbsp;&nbsp;&nbsp;  opis
</td>
<td>
<img src="showImage.php?i=images/doimage.jpg&w=100&h=60">
</td>


[Ovu poruku je menjao Nemanja Avramović dana 19.03.2016. u 11:31 GMT+1]
 
Odgovor na temu

[es] :: PHP :: Problem sa prikazivanjem slika

[ Pregleda: 794 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.