PHPackages                             ozznest/api-images - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. ozznest/api-images

ActiveSymfony-bundle[File &amp; Storage](/categories/file-storage)

ozznest/api-images
==================

Library to implement images to GraphQL API

v2.0.6(9y ago)04.4k↑66.7%MITPHPPHP &gt;=7.0.0

Since Jan 31Pushed 4y agoCompare

[ Source](https://github.com/ozznest/ApiImages)[ Packagist](https://packagist.org/packages/ozznest/api-images)[ RSS](/packages/ozznest-api-images/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (23)Used By (0)

API Images Bundle
=================

[](#api-images-bundle)

Symfony bundle for easy implementation images to your GraphQL API ( bundle with GraphQL implementation and its documentation is [here](https://github.com/Youshido/GraphQLBundle) ). Bundle provides `UploadImageMutation`:

```
mutation {
  uploadImage(field: "image") {
    id
    url
    resized(width: 100, height: 100, mode: INSET) {
      url
    }
  }
}
```

Mutation assumes that request content-type is `multipart/form-data` and include image data in field that is passed as argument `field`. Also bundle provides `ImageField` to use in your API like this:

```
{
  me {
    id
    firstName
    lastName
    image { // image field from bundle
      url
      resized(width: 100, height: 100, mode: INSET) {
        url
      }
    }
  }
}
```

or you can add arguments directly to the image field for your convenience.

```
{
  me {
    id
    firstName
    lastName
    small: image(width: 100, height: 100, mode: INSET) { // resized directly
      url
    }
    medium: image(width: 500, height: 300, mode: OUTBOUND) { // different mode
      url
    }
    fullSize: image {
      url
    }
  }
}
```

How to use
----------

[](#how-to-use)

- [Installation](#1-installation)
- [Configuration](#2-configuration)
- [Entity set-up](#3-set-up-your-entities)
    - [ORM way](#31-orm-set-up)
    - [ODM way](#31-odm-set-up)
- [GraphQL schema set-up](#4-set-up-graphql-schema)
    - [Mutation type](#41-add-uploadimagemutation-to-your-mutationtype)
    - [Custom type](#42-add-image-field-to-your-type)
    - [Resolver](#43-setupdate-image-in-your-field-resolver)

### 1. Installation:

[](#1-installation)

> composer require youshido/api-images

### 2. Configuration:

[](#2-configuration)

#### 2.1 Enable bundle in your `AppKernel.php`:

[](#21-enable-bundle-in-your-appkernelphp)

```
$bundles[] = new Youshido\ImagesBundle\ImagesBundle()
```

#### 2.2. Add new routing in `routing.yml`:

[](#22-add-new-routing-in-routingyml)

```
images:
    resource: "@ImagesBundle/Controller/"
    type:     annotation
```

#### 2.3. Configurate bundle in `config.yml`

[](#23-configurate-bundle-in-configyml)

```
images:
    web_root: "%kernel.root_dir%/../web" #your app web root
    path_prefix: "uploads/images"        #folder in web root where images will be stored
    platform: orm                        #orm or odm
    driver: gd                           #imagine driver, can be gd, imagick or gmagick
```

### 3 Set-up your entities

[](#3-set-up-your-entities)

#### 3.1 ORM set-up

[](#31-orm-set-up)

Add image property and implement `ImageableInterface` to your entity:

```
