开发者

php GD problem, black image created

开发者 https://www.devze.com 2023-02-25 02:00 出处:网络
i\'v been pulling my hair over this for a couple of hours now, i am working on an image cropping module for magento, it works fine on my localhost but when i upload the file online it doesn\'t work! g

i'v been pulling my hair over this for a couple of hours now, i am working on an image cropping module for magento, it works fine on my localhost but when i upload the file online it doesn't work! gd creates a black image.

i'v tried everything.. checked permission, file paths, and it doesn't show any errors..

here is the code that creates the image

<?php
    $id = $_GET['id'];
    $crop  = $_GET['crop'];
    $token  = $_GET['token'];

    if ($id !== '' && $crop !== '') {
    $crop    = explode(":", $crop);
    $product = Mage::getModel('catalog/product')->load($id);
    $file  = $product->getMediaCon开发者_JAVA百科fig()->getMediaUrl($product->getImage());
    $src = $file;
    $targ_w =  $crop[0];
    $targ_h = $crop[1];
    $img_r = imagecreatefromjpeg($src);
    $dst_r = imagecreatetruecolor( $crop[6], $crop[7] );
    imagecopyresampled($dst_r,$img_r, 0,0, $crop[2],$crop[3],  $crop[6],$crop[7],  $crop[6],$crop[7]);
    $dir = '../truecolor/images/'.$id.'/test/';
    if (!file_exists($dir)) {
    mkdir($dir, 0777);
    }
    $filename = '../truecolor/images/'.$id.'/test/sw_'.$id.'.jpg';
    if (file_exists($filename)) {
    unlink($filename);
    }
    imagejpeg($dst_r,$filename,100);
    ?>

would really appreciate any help with this..

SOLVED:

Ok i figured it out, and i feel kinda stupid :)

the server i was working on had an http authentication, which was preventing the image from being loaded by the php file..

works fine now!

0

精彩评论

暂无评论...
验证码 换一张
取 消