Resize the images on the client side in Drupal 7? - drupal-7

Is there any module which integrate with the image/file field module that allows me to resize the images on the client side in Drupal 7? My client has very big images and I prefer that he resizes them on the client side....
Thanks!

Install Plupload module for Drupal
Edit the file plupload.module
Add 'resize' => array('width' => '320', 'height' => '240', 'quality' => '90'), to #plupload_settings.
Example:
$element['filefield_plupload']['pud'] = array(
'#type' => 'plupload',
'#title' => t('Select one or more files to upload'),
// Even though filefield does validation on submit, this is required for
// client side validation as well as proper file munging during upload.
'#upload_validators' => $element['#upload_validators'],
'#plupload_settings' => array(
'cardinality' => $field['cardinality'],
'resize' => array('width' => '320', 'height' => '240', 'quality' => '90'),
Ref: Drupal Issue: plupload client side resize option

Plupload has that functionality:
Allows you to upload files using HTML5 Gears, Silverlight, Flash, BrowserPlus or normal forms, providing some unique features such as upload progress, image resizing and chunked uploads.
Handily enough a Plupload module for Drupal already exists.

Related

How to hide a custom user profile field on hook_disable in Drupal 7?

I have created a module that adds a field to the user profile. I used field_create_field and field_create_instance to do this. When I disable the module, I want the field to no longer show up on the user profile, but I do not want to destroy it. I want to be able to enable the module and have the field show up and the data to still be there as originally entered. Can anyone tell me how to accomplish this?
Here is the code I used to create the field:
$field = array(
'field_name' => $field_name,
'type' => 'text',
'visibility' => 1,
'category' => 'API',
);
$field = field_create_field($field);
$field_instance = array(
'field_name' => $field_name,
'entity_type' => 'user',
'bundle' => 'user',
'label' => t('API Token'),
'cardinality' => 1,
'translatable' => 0,
'description' => t('By using this API token, you agree to the site Terms and Conditions and to acknowledge that your submission does not include protected health information or personal identifiers.'),
'widget' => array(
'type' => 'text_textfield',
'weight' => 10,
),
'formatter' => array(
'label' => t('field formatter label'),
'format' => 'text_default'
),
'settings' => array(
),
);
When you have created field using drupal entity like user, node etc then on that entity crud operation automatically apply.
As you have used api to "field_create_field" field then it automatically create field using api of entity vise verse its delete field when you uninstalled module.
First tell me when you uninstall your custom module then your custom field deleted from profile.? If yes then it's difficult to handle your use case. If no then in system table of Drupal you get status of your module whether it's disable or enable if status is 0 then used form alter hook of user profile and hide field
I was not able to accomplish exactly what I wanted, but I ended up installing the field extra widgets module and hiding the field completely on the edit form. Then, I used hook menu alter to create a local task tabs and I display the field on that tab.

Enabling CORS in laravel using barryvdh/laravel-cors package?

I am working on a simple Angular application and I wish to have my back end data from an API I created myself in Laravel. The API is sending back data just fine. But since I am developing my Angular application separately, I have an error when I use a service in Angular to fetch my resource.
Error
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8001/airports. This can be fixed by moving the resource to the same domain or enabling CORS.
So now I have installed a package in Laravel which is supposed to solve the issue but I am not sure how to use it. The cofig file of the package looks like:
'defaults' => array(
'supportsCredentials' => false,
'allowedOrigins' => array(),
'allowedHeaders' => array(),
'allowedMethods' => array(),
'exposedHeaders' => array(),
'maxAge' => 0,
'hosts' => array(),
),
'paths' => array(
'api/*' => array(
'allowedOrigins' => array('*'),
'allowedHeaders' => array('*'),
'allowedMethods' => array('*'),
'maxAge' => 3600,
),
'*' => array(
'allowedOrigins' => array('*'),
'allowedHeaders' => array('Content-Type'),
'allowedMethods' => array('POST', 'PUT', 'GET', 'DELETE'),
'maxAge' => 3600,
'hosts' => array('api.*'),
),
),
I am still getting the same error. Now what is it that I have to different in order to allow CORS?
Note: I have WAMP installed. I am developing both my Angular application and Laravel API on the same local server.
I ran into something similar with EmberJS instead of Angular. Laravel setup looks correct but I think you need to enable CORS support in Angular.
From a Chrome developer tutorial:
A word on Content Security Policy
Unlike many other JS MVC frameworks,
Angular v1.1.0+ requires no tweaks to work within a strict CSP. It
just works, out of the box!
However, if you're using an older version of Angular between v1.0.1
and v1.1.0, you'll need tell Angular to run in a "content security
mode". This is done by including the ngCsp directive alongside ngApp:
<html data-ng-app data-ng-csp>
You can find the whole article here.

How can I create cached files within CakePHP Plugin?

I have created a plugin for CakePHP that I would like to generate cached files within its own plugin folder at /app/Plugin/MyPlugin/tmp/cache.
I have already cerated the MyPlugin/tmp/cache directory manually.
I have created a bootstrap file at /app/Plugin/MyPlugin/Config/bootstrap.php with the following content:
<?php
Cache::config('short', array(
'engine' => 'File',
'duration' => '+60 minutes',
'path' => 'Plugin/MyPlugin/tmp/cache',
'prefix' => 'cake_short_',
'mask' => 0666,
));
I have created a Shell script at /app/Plugin/MyPlugin/Console/Command/MyPluginShell.php with the following function:
<?php
...
public function get_listings() {
$listings = $this->Listing->find('all');
Cache::write('listings', $listings, 'short');
$this->out('Task Completed');
}
I can run get_listings from within the Cake console just fine and the Task completes, however there is no Cache file being created at /app/Plugin/MyPlugin/tmp/cache like I would expect.
On a side note, I have tried replacing 'path' => 'Plugin/MyPlugin/tmp/cache' with 'path' => CACHE just to see if it will appear in app/tmp/cache but haven't had any luck.
I have also created the /app/Plugin/MyPlugin/tmp/cache within the plugin.
Any help would be appreciated.
I figured it out.
I wasn't loading the plugin correctly within app/Config/bootstrap.php.
I was doing this (incorrect):
CakePlugin::load('MyPlugin', array('routes' => true));
Instead of this (correct):
CakePlugin::load('MyPlugin', array('routes' => true, 'bootstrap' => true));

Drupal 7, default_value for a file field in a custom form

I've created a formular where the user can upload an image using a file field. In another formular the user is able to change the image he previous uploaded.
So far I was able that the user can upload a new picture or let the field empty and the existing image remains. My question is, how do I show the user in a nice way which file he previously uploaded with the field? Setting a #default_value (#code below) does nothing for me.
//$smallimage = fid of image
$form['smallimage'] = array(
'#type' => 'file',
'#title' => t('Image'),
'#default_value' => $smallimage,
'#description' => t('Upload a file, allowed extensions: jpg, jpeg, png, gif'),
);
Edit:
Switched back to managed files. I've no types to bind my files/images to so I bind them to the first node and the first user. Not a clean solution but it works.
Has anyone a solution/workaround without switching to managed_file?
Thank you in advance
On Drupal FAPI, '#default_value' is not a valid property for type "file", if you want to use the property #default_value in that case you can use
'#type' => 'managed_file'
and your code should look like this,
$form['file'] = array(
'#title' => t('Upload image'),
'#type' => 'managed_file',
'#description' => t('Images must be one of jpg, bmp, gif or png formats.'),
'#default_value' => $fid, //here you need to provide the file id (get it from database or $file_obj->fid).
'#upload_location' => 'public://'
);

play media file or open image in browser cakephp

i am using cakephp 2.x i want to play the audio and open image in a browser ....
In my 'view' I have the following code which is correctly showing the filename, and displaying the download link and the file is successfully downloading
<?php echo $this->Html->link('Download', array('controller' => 'bugshot', 'action' => 'download', $files['Audio']['filename']));?>
now i want to play this audio file as well ..as i have two licks on the page ,,, first is download and tthe other is view or play
In my controller I have the following code that is downloading the file
public function download($filename) {
$idUser = $this->Auth->user('idUser');
$folder_url = APP.'uploads/'.$idUser.'/'.$filename;
$this->response->file($folder_url, array('download' => true, 'name' => $filename));
return $this->response;
}
Downloading and serving files is almost the same
Serving files via Cake can be done with one function similiar to the following:
public function download($filename) {
$download = !empty($_GET['download']); // <- example
$idUser = $this->Auth->user('idUser');
$folder_url = APP.'uploads/'.$idUser.'/'.$filename;
$this->response->file($folder_url, array('download' => $download, 'name' => $filename));
return $this->response;
}
That way requesting the url /.../this-file.mp3 will serve the file, whereas the url /.../this-file.mp3?dowload=1 will download it.
Audio is a html5 tag
The simplest way to serve audio, is to just use the audio tag:
<?php
$url = Router::url(array('controller' => 'x', 'action' => 'download', $name));
$download = Router::url(array('controller' => 'x', 'action' => 'download', $name, '?' => array('download' => 1)));
?>
<audio src="<?= $url; ?>" controls>
<!-- alternate content for unsupported case -->
Download Download it;
</audio>
Being a relatively new tag, support isn't universal - see Detailed article on support or other resources for more information on how to handle browsers that do not support this tag.
Or, use one of the many flash based media players that exist.

Resources