write image to file

@param resource $image  image
@param string $file  image file (JPEG or PNG)
@param int $type  file type (2:JPEG or 3:PNG)
@return void
@access protected
@uses errorMsg
484374
public function writeImage( $image, $file, $type) {
		switch ($type) {
			case 2:	//JPEG
			Imagejpeg( $image, $file);
			break;
			
			case 3:	//PNG
			Imagepng( $image, $file);
			break;
			
			default:
			$this->errorMsg="File format not supported.";
		}
	}
267716
public function add(string $file, string $type)
    {
        $url = self::ADD.$this->access_token.'&'.http_build_query([
                'type' => $type,
            ]);
        $this->curl->setOpt(CURLOPT_SAFE_UPLOAD, true);
        $data = $this->curl->post($url, [
            'media' => new \CURLFile($file),
        ]);

        return Response::json($data);
    }
784356
public function displayImage( $image, $type) {
		switch ($type) {
			case 2:	//JPEG
			header("Content-Type: image/jpeg");
			Imagejpeg( $image);
			break;
			
			case 3:	//PNG
			header("Content-Type: image/png");
			Imagepng( $image);
			break;
			
			default:
			$this->errorMsg="File format not supported.";
		}
	}
363520
private function setSelectedType($type)
    {
        $type = ( empty($type) || ! is_string($type) )
            ? $this->getDefaultType()
            : $type;

        if ( ! $this->isValidType($type) ) {
            throw new InvalidImageTypeException("The image type [{$type}] is invalid.");
        }

        $this->selected = $this->convert($type);
    }
191877
public function saveFile($data, $file)
    {
        $openfile = @fopen($file, "wb") or die("saveFile: Error opening file '{$file}'.");
        @fwrite($openfile, $data) or die("saveFile: Error writing data into file '{$file}'.");
        @fclose($openfile);
    }
1023644
public function saveImage( $type = NULL )
	{
		if( !$this->source )
			throw new RuntimeException( 'No image loaded' );
		if( !$this->target )
			throw new RuntimeException( 'No modification applied' );
		if( !$this->targetUri )
			throw new RuntimeException( 'No target image URI set' );
		$type	= $type ? $type : $this->sourceInfo[2];
		switch( $type )
		{
			case IMAGETYPE_GIF:
				return imagegif( $this->target, $this->targetUri );
			case IMAGETYPE_JPEG:
				return imagejpeg( $this->target, $this->targetUri, $this->quality );
			case IMAGETYPE_PNG:
				return imagepng( $this->target, $this->targetUri );
			default:
				throw new Exception( 'Image Type "'.$type.'" is no supported' );
		}
	}
501649
function store( $fileName, $filePath, $type )
    {
        if ( !$this->IsProcessed )
            $this->process();
        $imageObject = $this->imageObject();
        switch( $type )
        {
            case 'png':
            {
                if ( !file_exists( $filePath ) )
                {
                    eZDir::mkdir( $filePath, false, true );
                }
                $fileFullPath = eZDir::path( array( $filePath, $fileName ) );
                ImagePNG( $imageObject, $fileFullPath );
                $this->StoredPath = $filePath;
                $this->StoredFile = $fileName;
                $this->StoredType = $type;
                return true;
            } break;

            case 'jpg':
            {
                if ( !file_exists( $filePath ) )
                {
                    eZDir::mkdir( $filePath, false, true );
                }
                ImageJPEG( $imageObject, eZDir::path( array( $filePath, $fileName ) ) );
                $this->StoredPath = $filePath;
                $this->StoredFile = $fileName;
                $this->StoredType = $type;
                return true;
            } break;

            default:
            {
                eZDebug::writeError( 'Image format not supported: ' . $type, __METHOD__ );
            }
        }
        return false;
    }
208257
public static void writePng(Image image, ImageOutputStream destImageStream) throws IORuntimeException {
		write(image, IMAGE_TYPE_PNG, destImageStream);
	}
440214
public function attachImage($image)
    {
        $this->mms = true;

        if (is_array($image)) {
            $this->attachImages = array_merge($this->attachImages, $image);
        } else {
            $this->attachImages[] = $image;
        }
    }
1282364
public function doFilter($file, $arguments, $typeOptions)
    {
        $Imagine = new Imagine();
        $image = $Imagine->open($file);
        $colour = $image->palette()->color('#' . $arguments['colorize']);
        $image->effects()->colorize($colour);
        $image->save($file);
    }
759826
public function command(String $file, $type = 'Project')
    {
        $path     = $this->convertFileName($file);
        $pathEx   = explode('-', $path);
        $command  = $pathEx[0];
        $method   = $pathEx[1] ?? Config::get('Routing', 'openFunction') ?: 'main';

        $code = ' -r \'' . $this->directoryIndexCommand . '(new \\'.$type.'\Commands\\'.$command.')->'.$method.'();\'';

        $this->run($code);
    }
594725
public function open($type = 'image/jpeg')
    {
        switch ($type) {
            case 'image/jpeg':
                $image = imagecreatefromjpeg($this->file);
                break;
            case 'image/gif':
                $image = imagecreatefromgif($this->file);
                break;
            case 'image/png':
                $image = imagecreatefrompng($this->file);
                break;
            default:
                $image = null;
        }
        return $this->image = $image;
    }
1295434
public static void write (BufferedImage image, OutputStream out)
        throws IOException
    {
        DataOutputStream dout = new DataOutputStream(out);

        // write the image dimensions
        int width = image.getWidth(), height = image.getHeight();
        dout.writeInt(width);
        dout.writeInt(height);

        // write the color model information
        IndexColorModel cmodel = (IndexColorModel)image.getColorModel();
        int tpixel = cmodel.getTransparentPixel();
        dout.writeInt(tpixel);
        int msize = cmodel.getMapSize();
        int[] map = new int[msize];
        cmodel.getRGBs(map);
        dout.writeInt(msize);
        for (int element : map) {
            dout.writeInt(element);
        }

        // write the raster data
        DataBufferByte dbuf = (DataBufferByte)image.getRaster().getDataBuffer();
        byte[] data = dbuf.getData();
        if (data.length != width * height) {
            String errmsg = "Raster data not same size as image! [" +
                width + "x" + height + " != " + data.length + "]";
            throw new IllegalStateException(errmsg);
        }
        dout.write(data);
        dout.flush();
    }
643218
public static function write_log($chain, $type, $file="", $line=""){
        /*if(filesize(PATHAPP . 'logs/log.txt') > 100000){           
            $arch= fopen(PATHAPP . 'logs/log.txt', "w");
            fclose($arch); 
        }*/
        $arch = fopen(PATHAPP . 'logs/log-' . date('Y-m-d') . '.txt', "a+"); 
        if(ENOLA_MODE == 'HTTP'){
            fwrite($arch, "[".date("Y-m-d H:i:s.u")." ".filter_input(INPUT_SERVER, 'REMOTE_ADDR')." "." - $type ] ".$chain." - $file - $line \n");
        }else{
            fwrite($arch, "[".date("Y-m-d H:i:s.u")." MODE CLI "." - $type ] ".$chain." - $file - $line \n");
        }
        fwrite($arch, "---------- \n");
        fclose($arch);
    }
979374
public function upload($file, $type)
    {
        if (!$file || !$type) {
            $this->setError('参数缺失');

            return false;
        }

        if (!file_exists($file)) {
            $this->setError('文件路径不正确');

            return false;
        }

        $data          = [];
        $data['media'] = '@' . realpath($file);

        Api::setPostQueryStr('type', $type);

        $node = 'upload';

        $res = $this->_post($node, $data, false);

        return $res;
    }
1305093
function writeFile(callback) {
        var s = JSON.stringify(images);

        fs.writeFile('imageData.json', s, function (err) {
          if (err) return console.log(err);
          else
            { 
            console.log("success");
            if (callback) callback.call(this, images);
            }
        });


    }
351848
public static function create( $file, $type = null ) 
	{
		// when no type is given use the file extension
		if ( is_null( $type ) ) 
		{
			$type = CCStr::extension( $file );

			// validate type
			if ( !in_array( $type, static::$available_image_types ) )
			{
				$type = null;
			}
		}

		$image_data = getimagesize( $file );

		if ( $image_data === false ) 
		{
			return false;
		}

		$image = null;

		switch( $image_data['mime'] ) 
		{
			case 'image/gif':
				$image = imagecreatefromgif( $file );
			break;

			case 'image/jpeg';
				$image = imagecreatefromjpeg( $file );
			break;

			case 'image/png':
				$image = imagecreatefrompng( $file );
			break;

			default:
				// we dont support other image types
				return false;
			break;
		}

		// when the image type is still null we are going to use 
		// the mime type of the image 
		if ( is_null( $type ) )
		{
			$type = CCStr::suffix( $image_data['mime'], '/' );
		}

		return new static( $image, $type );
	}